PowerCLI

 View Only
  • 1.  Execute PowerCLI Script

    Posted Jul 31, 2017 12:12 PM

    How do you call another Script and execute that?

    I have with me two .ps1 files. script1.ps1 and script2.ps1

    From script1.ps1, I want to call script2.ps1 and execute the script.



  • 2.  RE: Execute PowerCLI Script
    Best Answer

    Posted Jul 31, 2017 12:20 PM

    You can just call the script through the Invoke-Expression cmdlet.

    It can be a relative path (if you are located in the folder) or an absolute path

    $script2 = ".\two.ps1"

    Invoke-Expression -Command $script2

    $script3 = "C:\Scripts\two.ps1"

    Invoke-Expression -Command $script3



  • 3.  RE: Execute PowerCLI Script

    Posted Jul 31, 2017 12:30 PM

    This works.. thank you



  • 4.  RE: Execute PowerCLI Script

    Posted Jan 28, 2019 02:49 PM

    Is it possible to run "script2" in a new powercli window?



  • 5.  RE: Execute PowerCLI Script

    Posted Jan 28, 2019 02:55 PM

    Not sure what you mean by "another PowerCLI window"?

    You start a PowerShell session, and the PowerCLI modules are auto-loaded when a PowerCLI cmdlet is used.

    Unless you mean something else.



  • 6.  RE: Execute PowerCLI Script

    Posted Jan 28, 2019 03:03 PM

    I run all my vm scripts in powercli, but that I mean a "VMWare vSphere PowerCLI 5.5 Release 1" window. See image.

    In all honesty, I'm still a bit confused on exactly what PowerCLI is vs Powershell. I know that vm scripts can be run in "normal" powershell, but I could only ever get things to work for me when I started using PowerCLI. In any event, I'd like the secondary scripts to open in a "VMWare vSphere PowerCLI" window instead of a "normal" Powershell window.



  • 7.  RE: Execute PowerCLI Script

    Posted Jan 28, 2019 04:02 PM

    PowerCli is run on top of PowerShell.

    But you are using a very old version of PowerCLI.
    In fact, you should consider upgrading.

    See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates