K B
asked on
POWERSHELL: do / until, should continue even when there is an error
Effectively, I am waiting till the VMs are in a state where my script can continue to action upon them. However, the VMs are not quite built by the time this loop looks for them (in other words, there is NO status yet).
How do I force the script to keep checking "until" the statuses are obtained for the VMs (thus ending the DO/UNTIL)
Thank you!
Here is the error:
How do I force the script to keep checking "until" the statuses are obtained for the VMs (thus ending the DO/UNTIL)
Thank you!
function WaitforAllRunning($vmName)
{
do {
Start-Sleep -milliseconds 100
$vmStatuses = Get-AzureRmVM -VM $vmName -ResourceGroupName $rgName -Status -ErrorAction SilentlyContinue | select -ExpandProperty Statuses | Select -ExpandProperty DisplayStatus
$vmStatus0 = $VMStatuses[0]
$vmStatus1 = $VMStatuses[1]
$vmStatusC = Get-AzureRmVM -VM $vmName -ResourceGroupName $rgName -Status -ErrorAction SilentlyContinue | select -ExpandProperty Statuses | Select -ExpandProperty Code
$vmCode = $vmStatusC[0]
}
until ({$vmStatus0 -eq 'Provisioning succeeded'} -and {$vmStatus1 -eq 'VM running'} -and {$vmCode = 'ProvisioningState/succeeded'})
}
Here is the error:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In case you haven't found it yet yourself - just noticed that I missed something: In line 13, the test for $vmCode should of course be "-eq" instead of "=":
} Until (($vmStatus0 -eq 'Provisioning succeeded') -and ($vmStatus1 -eq 'VM running') -and ($vmCode -eq 'ProvisioningState/succeeded'))
ASKER
Thank you. Made the adjustment.. it is working well.
ASKER
Thank you! I have spent days trying to figure it out on my own.
I will also study what you have so graciously provided and attempt to learn from it.