I have noticed, that when you run some powercli commands like "stop-vm" or "start-vm" within an inoke-command, the command will just hang. The command will not finish, because (as I noticed), the invoke-command does not know what to do with the returnvalue of "start/stop-vm)
for example, the following will work:
$Scriptblock = {
Connect-VIServer -Server vCenter01 -Credential (Get-Credential)
$crazy = Stop-VM VM01 -Confirm:$false
$crazy = Start-VM VM01
}
Invoke-Command -computer RemoteServer01 -scriptblock $Scriptblock
but this code will not work, because the start/stop command has not variable:
$Scriptblock = {
Connect-VIServer -Server vCenter01 -Credential (Get-Credential)
Stop-VM VM01 -Confirm:$false
Start-VM VM01
}
Invoke-Command -computer RemoteServer01 -scriptblock $Scriptblock
Can anyone explain me this behaviour?
Thanks.
This seems to work for me (with PSv5.1 and PowerCLI 12.7)
Which PowerShell versions (localhost and RemoteServer01) and PowerCLI version (RemoteServer01) are you using?
And which OS is running on RemoteServer01?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your quick cross-check
Powershell-Version: 5.1.14393.5127 (Local and Remote server)
PowerCli-Version: 12.2.0 build 17538434
Can you try upgrading the PowerCLI on the Remote Server?
Or eventually try with another Remote server that has a later PowerCLI version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have updated the PowerCli Version now to 12.7, but still same issue.
I did notice you seem to also have an older PS version, I tested with 5.1.19041.1682
Do you have a clean PowerCLI installation?
What does this return?
Get-Module -Name VMware* -ListAvailable
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference