I have a script that updates hba firmware. I first wan't to put the server into maintenance mode.
$task1 = get-vmhost esx1.example.com | set-vmhost -state maintenance
wait-task -task $task1
I get a:
Wait-Task : Cannot bind parameter 'Task'. Cannot conver esx1.example.com to "Vmware.VimAutomation.Types.Task"
How to use Wait-Task properly
There were some issues reported with Wait-Task in the past.
You could try the EnterMaintenanceMode_Task method.
$esx = Get-VMHost <ESX-hostname> | Get-View $taskMoRef = $esx.EnterMaintenanceMode_Task(0, $true) $task = Get-View $taskMoRef while ($task.Info.State -eq "running" -or $task.Info.State -eq "queued") { sleep 2 $task = Get-View $taskMoRef }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at .
You could use the script I posted there or even better the Get-VIObjectByVIView cmdlet Carter suggested.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I looked at the Get-VIObjectByVIView, but i have no clue how to use it.:0
Hi,
Set-VMHost returns VMHost object and there is not need to pass the result to wait-task cmdlet.
If you want to call explicitly wait-task you should use RunAsync parameter
$vmhost = get-vmhost esx1.example.com | set-vmhost -state maintenance
is equal to
$task1 = get-vmhost esx1.example.com | set-vmhost -state maintenance -RunAsync $vmhost = Wait-Task $task1
Regards,
Yasen
Sorry Rob, I didn't notice you used a cmdlet.
The other post is useful when you use a SDK method.
In your case it is rather straightforward.
You run the cmdlet with the -RunAsync parameter, capture the TaskImpl object and use that in the Wait-Task cmdlet.
$task = Get-VMHost <ESX-hostname> | Set-VMHost -State maintenance -RunAsync Wait-Task -Task $task
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wait-Task works with -runasync
Unfortunally, the script continues, that's not what i want.
The server must be in maintenance mode, before the script continues, because hba firmware gets updated.
There were some issues reported with Wait-Task in the past.
You could try the EnterMaintenanceMode_Task method.
$esx = Get-VMHost <ESX-hostname> | Get-View $taskMoRef = $esx.EnterMaintenanceMode_Task(0, $true) $task = Get-View $taskMoRef while ($task.Info.State -eq "running" -or $task.Info.State -eq "queued") { sleep 2 $task = Get-View $taskMoRef }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc i was looking for that.