While not entering loop

Copper Contributor

Hi community,

i want to shutdown a windows server to take a vmware snapshot.

So I have to check if the vm is powered down on esx.




# connect-VIServer -Server

$computer = "vm-sql"

Stop-Computer $computer -Force -Confirm:$false

$vm = Get-VM $computer

$vmstate = $vm.PowerState


while ($vmstate -eq 'PoweredOff') {

        Start-Sleep -Seconds 5
        Write-Host "$computer is $($vm.PowerState)"
        $vmstate = (get-vm $vm).PowerState
Write-Host "VM down"




 The problem is that never entering the loop. All properties and variables are correct.


After the script this condition is true. So it schuld be fine.




$vmstate -eq "PoweredOff"




I think it has something to do, that the condition ist with a string?!


Any help will be wonderfull.


2 Replies
best response confirmed by Skyscraper19 (Copper Contributor)



Wouldn't you want line 14 to be:



while ($vmstate -ne 'PoweredOff') {





@LainRobertson You are right