VMware Cloud Community
wolficool
Contributor
Contributor
Jump to solution

Update-Tools and become the Task Result back

Hello,

i want to Update the VMware Tools and become the vCenter Task Result back if it was Canceled, Error, or Successfully.

I have tried the Following, but i ever become back:

Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

$task = Get-View -Id (Update-Tools -VM $Vm).Id

Write-Verbose "Wait up to $timeoutSeconds seconds until Update VMWare Tools task is finished..."
while ((New-TimeSpan -Start $startDate -End (Get-Date)).TotalSeconds -lt $timeoutSeconds -and ($task.Info.State -eq [VMware.Vim.TaskInfoState]::running -or $task.Info.State -eq [VMware.Vim.TaskInfoState]::queued)) {
Start-Sleep 10
$task.UpdateViewData()
}

if ($task.Info.State -eq [VMware.Vim.TaskInfoState]::running) {
Write-Verbose "Canceling Update VMWare Tools task after $timeoutSeconds seconds."
$task.CancelTask()
}
elseif ($task.Info.State -eq [VMware.Vim.TaskInfoState]::error) {
Write-Error "ERROR: Could not Update VMWare Tools for VM $VmName. :-("
}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You didn't use the RunAsync switch.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

You didn't use the RunAsync switch.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Thx a lot, i missed here Something 😉

The Id Error dont exists anymore.

The Tools are Updated, but i become back:

 ERROR: Could not Update VMWare Tools for VM tools-update. 😞

Thats the Output from:

elseif ($task.Info.State -eq [VMware.Vim.TaskInfoState]::error) {
Write-Error "ERROR: Could not Update VMWare Tools for VM $VmName. :-("

But the Task for the Update Tools was successfully...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you check what actually is in $task.Info after the UpdateViewData call?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

In the $task.Info.State says error.

In the vCenter the Task says: Cannot complete operation because VMware Tools is not running in this virtual machine.

But the VMware Tools are now updated on the VM.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I wanted to see what is in $task.Info, not $task.Info.State only.

But this is something that has been around for quite a while.
No clear, single explanation for this behaviour afaik.
You might want to check if there is anything in the logs (see KB1007873 for location).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos