Hello I'm having a bit of problem with the Invoke-VMScript cmdlet I have made a script that creates a virtual Windows 7 machine and then some powershell script executes on the machine for example renaming the computer to the correct name.
But if I run
Invoke-VMScript -ScriptText {(Get-Wmiobject -Class Win32_ComputerSystem).Rename($strName)}
The $strName variable doesn't get resolved, anyone have any idea on how to do this?
Your haven't correctly scoped your variable. Here's a simple experiment you can try in your console:
Invoke-VMScript's documentation suggests you should pass
-ScriptText
as a string instead of a ScriptBlock. So in this case, we can mimic example 2:Variables enclosed by
" "
will be resolved.