Forum Discussion

Skyscraper19's avatar
Skyscraper19
Copper Contributor
Oct 21, 2022

While not entering loop

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 vm-vcenter001.contoso.com

$computer = "vm-sql"

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

$vm = Get-VM $computer

$vmstate = $vm.PowerState

$vmstate


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.

 

Resources