1

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..

1 Answer 1

1

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.