VMware Cloud Community
m_agi
Contributor
Contributor
Jump to solution

Execute PowerCLI Script

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.

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
m_agi
Contributor
Contributor
Jump to solution

This works.. thank you

Reply
0 Kudos
Sharkie405
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Sharkie405
Contributor
Contributor
Jump to solution

2019-01-28 10_00_14-Window.png

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos