AK26
AK26

Reputation: 31

Calling a powershell script from a powercli script using invoke-vmscript?

I am attempting to execute a .ps1 on multiple VM's using the invoke-VMScript function. Currently I have the code: Invoke-VMScript -ScriptText $script -VM $servername -guestcredential $gcred -hostcredential $hcred and have $script = 'data.ps1' however this returns the error stating that 'data.ps1' is not a valid function or script. Any help is greatly appreciated.

Upvotes: 0

Views: 5902

Answers (2)

Nate Hekman
Nate Hekman

Reputation: 6657

I'm not set up to test this, but I would guess that -ScriptText needs to be given the full path to a .ps1 file accessible on the VM.

$script = '"C:\my scripts\data.ps1"'
Invoke-VMScript -ScriptText $script -VM $servername -guestcredential $gcred -hostcredential $hcred

Upvotes: 1

Piotr Stapp
Piotr Stapp

Reputation: 19830

You have to put in script variable content of your script, not file name.

Upvotes: 0

Related Questions