Hello,
I'm getting an error with the command Stop-VM.
This is the script i'm trying to run :
&{foreach($vm in Get-Folder "Sandbox" | Get-VM)
{
if ($vm.PowerState -eq "poweredOn"){
$vm | Stop-VM -Kill -Confirm:$false
}
}
}
and here is the error i'm getting :
I get the same error with
&{foreach($vm in Get-Folder "Sandbox" | Get-VM)
{
if ($vm.PowerState -eq "poweredOn"){
Stop-VM -VM $vm.Name -Kill -Confirm:$false
}
}
}
For info I'm running this script from a VM (Ubuntu 16.04) and I'm using VMware.PowerCLI 10.0.0.7895300, Powershell v6.0.2 and a vCenter 5.5.
Thanks
Did you display the content of the $vm variable in the loop?
From the error message it seems to contain a MoRef, instead of a VirtualMachine object
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's what I get if I display the content of $vm :
Thanks for the quick answer
That looks ok.
Can you try as follows?
foreach($vm in (Get-Folder "Sandbox" | Get-VM))
{
if ($vm.PowerState -eq "poweredOn"){
Stop-VM -VM $vm -Kill -Confirm:$false -Verbose
}
}
And like this
Get-Folder -Name "Sandbox" |
Get-VM |
where{$_.PowerState -eq 'poweredon'} |
Stop-VM -Kill -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's what I got with the first script :
It's the same Verbose and Error with every VM that's powered on.
And for the second one :
The first two errors seems new and the rest of the execution produce the same error text as the third one.
Strange, not sure what is happening here.
Would you mind attaching the newtest.ps1 file(s) you used?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That looks fine.
I suspect you might be hitting a bug.
I suggest to open a SR.
Is there any other platform (Windows/Mac) from which you could try the same?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried it on a Windows 7 with the same setup (latest version of Powershell and PowerCLI).
Here's the error :
(for some reason my script didn't ran so I just tried it with one VM).
It's the same error (but in french because of the OS). And it appeared even with the full name typed instead of the variable $vm.
How can I open a SR ?
Thanks
That is really strange, I have PowerCLI 10 on a Windows 10 box with PowerShell 6.0.1, and run it against a vSphere 6.5U1.
There everything seems to work alright.
So I think it must be the PowerShell version or the vSphere version.
Since PowerCLI 10 supports vSphere 5.5, it might be the newer PowerShell version.
Also note that the PowerCLI 10 Release Notes explicitly mention PowerShell Core 6.0.1
For the SR see How to File a Support Request
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Same thing with PowerShell Core 6.0.1 on my Ubuntu 16.04.
I'll try to set up a Windows 10 environment and run some test, and if that doesn't work I'll open a Support Request.
Thanks a lot for your time and help.