I am trying to run this script to patch a esxi host with update manager but the script quits before the host comes back online
$DC = read-host "Enter the Datacenter to patch"
$vmhost = get-vmhost -Location (Get-Datacenter $dc) | ?{$_.name -like "*r640*"}
$VMs = get-datacenter $dc | get-vm | ?{$_.powerstate -eq "Poweredon"}
$baseline = get-baseline -Name *Critical*
foreach ($vm in $VMs) {
Shutdown-VMGuest -VM $vm -Confirm:$false
$counter = 0
while($vm.PowerState -eq 'PoweredOn'){
if ($counter -gt 180) {
$vm = Get-VM -Name $vm.Name
stop-vm -vm $vm -confirm:$false
} else {
sleep 5
$vm = Get-VM -Name $vm.Name
$counter+=5
}
}
}
set-vmhost -VMHost $vmhost -State Maintenance -Confirm:$false
$baseline | Attach-Baseline -entity $vmhost -Confirm:$false
Scan-Inventory -Entity $vmhost
$UpdateTask = Update-Entity -Baseline $baseline -Entity $vmhost -RunAsync -Confirm:$false -ErrorAction Stop
while ($UpdateTask.percentcomplete -ne 100) {
Write-Progress -Activity "Patching $vmhost" -PercentComplete $updatetask.PercentComplete -Status "$($UpdateTask.PercentComplete) %"
Start-Sleep 5
$Updatetask = Get-Task -Id $Updatetask.id
}
get-vmhost -name $vmhost | set-vmhost -state Connected -Confirm:$false
$vms | start-vm -Confirm:$false
any idea?
What error do you get from the script?
Did you try to adapt the WebOperationTimeoutSeconds with the Set-PowerCLIConfiguration cmdlet?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this is the error I keep seeing
Did you check what is in $UpdateTask?
You're hitting the difference between a Client-Side task and a Server-Side task.
There is no Id property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
how do i find that while script is running
Just put the variable on a line on its own after the line where you populate it.
The content will appear on the console
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
here it is
That doesn't really help.
You have 3 error messages I can see, but only one display of the variable.
I would expect the content before each error message
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference