Question

I am this weird problem while working with powershell.When I run a while loop to check if the VM tools status, it gets stuck inside only. Here's the code:

Connect-VIServer $vmserver -User $vmuser -Password $vmpass
$status1 = (Get-VM  -Name $vmname).Extensiondata.Summary.Guest.ToolsStatus 
Write-Host $status1

while(!($status1 -eq 'toolsOK')){
Write-Host "tool status is:" $status1
Start-Sleep -Seconds 5
}

Write-Host "success"

I ran this code when that machine was off and in b/w started that machine($vmname).While it was swtiched off it's understood that "tool status is:"toolsNotRunning.But even after getting switched on and getting the remote of machine it shows same status,whereas I checked in ESXI status was running.I tried the above mentioned thing like it might get stuck so pressed ENTER,Mouse click etc,but no USE..I am using powershell ISE-host,version3.0..

Était-ce utile?

La solution

You're only running the update-code once. The while loop only runs the sleep command and write-host (which will never change).. try this:

Connect-VIServer $vmserver -User $vmuser -Password $vmpass

do {
    #This will min. once, until $status is 'toolsOK'
    $status1 = (Get-VM  -Name $vmname).Extensiondata.Summary.Guest.ToolsStatus

    if($status1 -ne 'toolsOK') { 
        Write-Host "tool status is:" $status
        Start-Sleep -Seconds 5
    }
}
until($status1 -eq 'toolsOK')

Write-Host "success"

or

Connect-VIServer $vmserver -User $vmuser -Password $vmpass
$status1 = (Get-VM  -Name $vmname).Extensiondata.Summary.Guest.ToolsStatus

while ($status1 -ne 'toolsOK') {
    Write-Host "tool status is:" $status
    Start-Sleep -Seconds 5

    $status1 = (Get-VM  -Name $vmname).Extensiondata.Summary.Guest.ToolsStatus
}

Write-Host "success"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top