VMware Cloud Community
NathanGO
Contributor
Contributor

Issues with Stop-VM

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 :

Stop-VM_Error.png

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

Tags (2)
Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership

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

Reply
0 Kudos
NathanGO
Contributor
Contributor

Here's what I get if I display the content of $vm :

Contentofvm.png

Thanks for the quick answer

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
NathanGO
Contributor
Contributor

Here's what I got with the first script :

Stop-VM_Error_2.png

It's the same Verbose and Error with every VM that's powered on.

And for the second one :

Stop-VM_Error_3.png

The first two errors seems new and the rest of the execution produce the same error text as the third one.

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
NathanGO
Contributor
Contributor

Sure, I've censored the IP address and the login/password but the rest is the same.

Again, thanks a bunch for your help.

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
NathanGO
Contributor
Contributor

I tried it on a Windows 7 with the same setup (latest version of Powershell and PowerCLI).

Here's the error :

Stop-VM_Error_4.png

(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

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
NathanGO
Contributor
Contributor

Same thing with PowerShell Core 6.0.1 on my Ubuntu 16.04.

Stop-VM_Error_5.png

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.

Reply
0 Kudos