I am a VMWare Workstation user with beginner experience in PowerShell, so I'm not a sysadmin or anything.
I found a script to revert and start a VM locally and am trying to use it remotely. I can revert just fine, but nothing happens when I try to start the VM. In the example below, $VMHostMachine is just my localhost for testing purposes. If I remove the -Session parameter from Invoke-Command, it works perfectly, so I know the script is right. Why doesn't it work when I try to invoke the command through a session?
Get-PSSession | Remove-PSSession
$VMHostMachine | New-PSSession
$rs = Get-PSSession
Write-Debug ("Now starting VM on host: " + $VMHostMachine)
$script = {param($VMImagePath, $VMConsolePath);
$QuotedVMPath = "`"{0}`"" -f $VMImagePath
$Result = Start-Process -FilePath $VMConsolePath -ArgumentList "-T", "ws", "start", $QuotedVMPath -Wait -PassThru -NoNewWindow
}
Invoke-Command -Session $rs -ScriptBlock $script -ArgumentList $vmConfig.VMImagePathOnHost, $vmConfig.VMRunUtiltyPath