Hi LucD,
After adding timeout in Update-Tools task and stopping the VM with multiple tries the below script was executed on 15 templates and waited for 72 hrs but script never completes even though invoke-vmscript executed on the machines. I think it was struck in some loop. I was unable to find on which loop its got hang can you please help. I am attaching the transcript file.
I have manually cancelled the script and Initially I thought the windows updates are still in progress but when I check manually on vms however no task is pending.
$CurrentDate = Get-Date -Format 'MM-dd-yyyy_hh-mm-ss'
Start-Transcript -Path "C:\My Data\Notepad++\$($CurrentDate)logfile.txt" -NoClobber -Force -Confirm:$false
$script = @'
$finalresult=@()
if(-not (Get-NetIPAddress |?{$_.IPAddress -match "153.71.1"})){
$finalresult+="DHCP IP Not Assigned"
}
else{
$ErrorActionPreference = "SilentlyContinue"
If ($Error) {
$Error.Clear()
}
$Today = Get-Date
$UpdateCollection = New-Object -ComObject Microsoft.Update.UpdateColl
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$Session = New-Object -ComObject Microsoft.Update.Session
$Result = $Searcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
If ($Result.Updates.Count -EQ 0) {
$finalresult+= "There are no applicable updates for this computer."
}
Else {
For ($Counter = 0; $Counter -LT $Result.Updates.Count; $Counter++) {
$DisplayCount = $Counter + 1
$Update = $Result.Updates.Item($Counter)
$UpdateTitle = $Update.Title
}
$Counter = 0
$DisplayCount = 0
$Downloader = $Session.CreateUpdateDownloader()
$UpdatesList = $Result.Updates
For ($Counter = 0; $Counter -LT $Result.Updates.Count; $Counter++) {
$UpdateCollection.Add($UpdatesList.Item($Counter)) | Out-Null
$ShowThis = $UpdatesList.Item($Counter).Title
$DisplayCount = $Counter + 1
$Downloader.Updates = $UpdateCollection
$Track = $Downloader.Download()
If (($Track.HResult -EQ 0) -AND ($Track.ResultCode -EQ 2)) {
$finalresult+="Download Status:SUCCESS"
}
Else {
$finalresult+="Download Status: FAILED With Error -- $Error()"
$Error.Clear()
}
}
$Counter = 0
$DisplayCount = 0
$Installer = New-Object -ComObject Microsoft.Update.Installer
For ($Counter = 0; $Counter -LT $UpdateCollection.Count; $Counter++) {
$Track = $Null
$DisplayCount = $Counter + 1
$WriteThis = $UpdateCollection.Item($Counter).Title
$Installer.Updates = $UpdateCollection
Try {
$Track = $Installer.Install()
$finalresult+="Update Installation Status:SUCCESS"
}
Catch {
[System.Exception]
$finalresult+= "Update Installation Status: FAILED With Error -- $Error()"
$Error.Clear()
}
}
}
}
$finalresult -join ','
'@
$tasks = @()
$alltemplates=Get-Datacenter WTR | Get-Template |?{$_.ExtensionData.Guest.GuestFullName -match 'windows' -and $_.ExtensionData.runtime.connectionstate -eq 'connected'} |select -First 15 |Select-Object @{N='Name';E={$_.Name}},@{N="Portgroup";E={((Get-View -Id $_.ExtensionData.Network).name)}},@{N="vCenter";E={([System.Net.Dns]::GetHostEntry($_.Uid.Split(“:”)[0].Split(“@”)[1])).HostName}}
$alltemplates|Export-Csv -Path "C:\My Data\CSV Output\$($CurrentDate)-first5templateswindows.csv" -NoTypeInformation -NoClobber
foreach($singletemplate in $alltemplates){
Set-Template -Template $singletemplate.Name -ToVM -Confirm:$false |fl
$templatevm= Get-VM $singletemplate.Name
$dhcpportgroup=Get-VirtualPortGroup -VMHost $templatevm.VMHost |?{$_.ExtensionData.config.DefaultPortConfig.Vlan.VlanId -eq '2067'}
$nic=Get-NetworkAdapter -VM $templatevm.Name
if($nic -eq $null){
New-NetworkAdapter -VM $templatevm.Name -Portgroup $dhcpportgroup -Type Vmxnet3 -StartConnected -Confirm:$false
}
Get-NetworkAdapter -VM $templatevm.Name |Set-NetworkAdapter -Portgroup $dhcpportgroup -Confirm:$false |fl
Start-VM -VM $templatevm.Name -Confirm:$false |fl
while($templatevm.ExtensionData.Guest.GuestOperationsReady -ne "True"){
Start-Sleep -Seconds 3
$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
}
if($templatevm.ExtensionData.guest.toolsversionstatus -eq 'guestToolsNeedUpgrade'){
$timeoutSeconds = 600
$start = Get-Date
$task = Get-View -Id (Update-Tools -VM $templatevm.Name -NoReboot -RunAsync).Id
while((New-TimeSpan -Start $start -End (Get-Date)).TotalSeconds -lt $timeoutSeconds -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::running -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::queued){
Sleep 5
$task.UpdateViewData()
}
if($task.Info.State -eq [VMware.Vim.TaskInfoState]::running){
$task.CancelTask()
}
elseif($task.Info.State -eq [VMware.Vim.TaskInfoState]::error){
Write-Error "Update Tools failed"
}
}
while($templatevm.ExtensionData.Guest.GuestOperationsReady -ne "True"){
Start-Sleep -Seconds 3
$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
}
$sInvoke = @{
VM = $templatevm.Name
GuestUser = 'administrator'
GuestPassword = ''
ScriptText = $script
ScriptType = 'Powershell'
RunAsync = $true
Confirm = $false
}
$tasks += @{
VM = $templatevm.Name
Task = Invoke-VMScript @sInvoke
}
}
while($tasks.Task.State -contains 'Running'){
sleep 2
}
$report=@()
$csvFiles = @()
foreach ($task in $tasks) {
$vm=Get-VM -Name $task.VM
Stop-VMGuest -VM $vm.Name -Confirm:$false
while($vm.ExtensionData.Runtime.PowerState -ne 'poweredOff'){
Start-Sleep -Seconds 1
$vm.ExtensionData.UpdateViewData("Runtime.Powerstate")
}
Start-VM -VM $vm.Name -Confirm:$false
$vm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
while($vm.ExtensionData.Guest.GuestOperationsReady -ne "True"){
Start-Sleep -Seconds 1
$vm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
}
$maxCount = 3
$count = 0
while($count -lt $maxCount -and $vm.PowerState -ne 'PoweredOff' ){
Stop-VMGuest -VM $vm -Confirm:$false |fl
$count++
Sleep 300
$vm = Get-VM -Name $vm.Name
}
if($vm.PowerState -ne 'PoweredOff'){
Stop-VM -VM $vm -Confirm:$false |fl
}
$report+= $task | Select @{N='VM';E={$_.VM}},
@{N='State';E={$_.Task.State}},
@{N='Error';E={$_.Task.TerminatingError.Message}},
@{N ='Result'; E={$_.Task.Result.ScriptOutput.Split("`n") |Where-Object { $_ -ne '' } | %{$_.Trim("`r`n")}}}
}
$filename = "C:\AllTemplatepatchstatusreport.csv as on dated $($CurrentDate).csv"
$csvFiles += $filename
$report |Export-Csv -Path $filename -NoTypeInformation -NoClobber -UseCulture
Send-MailMessage -From "" -To "" -Subject "Script POC Template Patching" ` -Body "The attachment contains templates patching status" ` -Attachments $csvFiles -SmtpServer ''
$alltemplates |ForEach-Object -Process {
Get-NetworkAdapter -VM $_.name |Set-NetworkAdapter -NetworkName $_.Portgroup -Confirm:$false
Set-VM -VM $_.Name -ToTemplate -Confirm:$false
}
Stop-Transcript
errors on powershell console:
I think I found what is happening.
The condition in the Where-clause is incorrect.
There are 2 conditions to stay inside the Where loop:
Instead of the -or, those conditions should be combined with an -and
while((New-TimeSpan -Start $start -End (Get-Date)).TotalSeconds -lt $timeoutSeconds -and
($task.Info.State -eq [VMware.Vim.TaskInfoState]::running -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::queued)){
Sleep 5
$task.UpdateViewData()
}
if($task.Info.State -eq [VMware.Vim.TaskInfoState]::running){
$task.CancelTask()
}
elseif($task.Info.State -eq [VMware.Vim.TaskInfoState]::error){
Write-Error "Update Tools failed"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Without actually being able to see the environment, this is hard to analyse the issue.
I would suggest testing this for only 1 VM (the one for which Stop-VMGuest didn't seem to work).
You could include some more info in the script (some Write-Host lines with extra info).
Also, it could help to check before launching a command if there are any background tasks running against that specific VM.
But again, with only the information in this thread, it is hard to analyse the issue.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok I will give a try and update here
Hi LucD,
This time I tested only on 5 templates by adding write-host on each change in the script. On the first vm itself I found the issue with $timeoutSeconds which we added for vmware tools.
I can see tools got updated for the below vm and showing current version but the script never moved to next line.
No Background tasks are running on the VM. I have checked by launching new powershell console and it shows guest operation ready is true.
Script:
$CurrentDate = Get-Date -Format 'MM-dd-yyyy_hh-mm-ss'
$logfilelocation="C:\My Data\Notepad++\$($CurrentDate)logfile.txt"
Start-Transcript -Path $logfilelocation -NoClobber -Force -Confirm:$false
$script = @'
$finalresult=@()
if(-not (Get-NetIPAddress |?{$_.IPAddress -match "153.71.1"})){
$finalresult+="DHCP IP Not Assigned"
}
else{
$ErrorActionPreference = "SilentlyContinue"
If ($Error) {
$Error.Clear()
}
$Today = Get-Date
$UpdateCollection = New-Object -ComObject Microsoft.Update.UpdateColl
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$Session = New-Object -ComObject Microsoft.Update.Session
$Result = $Searcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
If ($Result.Updates.Count -EQ 0) {
$finalresult+= "There are no applicable updates for this computer."
}
Else {
For ($Counter = 0; $Counter -LT $Result.Updates.Count; $Counter++) {
$DisplayCount = $Counter + 1
$Update = $Result.Updates.Item($Counter)
$UpdateTitle = $Update.Title
}
$Counter = 0
$DisplayCount = 0
$Downloader = $Session.CreateUpdateDownloader()
$UpdatesList = $Result.Updates
For ($Counter = 0; $Counter -LT $Result.Updates.Count; $Counter++) {
$UpdateCollection.Add($UpdatesList.Item($Counter)) | Out-Null
$ShowThis = $UpdatesList.Item($Counter).Title
$DisplayCount = $Counter + 1
$Downloader.Updates = $UpdateCollection
$Track = $Downloader.Download()
If (($Track.HResult -EQ 0) -AND ($Track.ResultCode -EQ 2)) {
$finalresult+="Download Status:SUCCESS"
}
Else {
$finalresult+="Download Status: FAILED With Error -- $Error()"
$Error.Clear()
}
}
$Counter = 0
$DisplayCount = 0
$Installer = New-Object -ComObject Microsoft.Update.Installer
For ($Counter = 0; $Counter -LT $UpdateCollection.Count; $Counter++) {
$Track = $Null
$DisplayCount = $Counter + 1
$WriteThis = $UpdateCollection.Item($Counter).Title
$Installer.Updates = $UpdateCollection
Try {
$Track = $Installer.Install()
$finalresult+="Update Installation Status:SUCCESS"
}
Catch {
[System.Exception]
$finalresult+= "Update Installation Status: FAILED With Error -- $Error()"
$Error.Clear()
}
}
}
}
$finalresult -join ','
'@
$tasks = @()
$alltemplates=Get-Datacenter WTR | Get-Template |?{$_.ExtensionData.Guest.GuestFullName -match 'windows' -and $_.ExtensionData.runtime.connectionstate -eq 'connected'} |select -First 15 |Select-Object @{N='Name';E={$_.Name}},@{N="Portgroup";E={((Get-View -Id $_.ExtensionData.Network).name)}},@{N="vCenter";E={([System.Net.Dns]::GetHostEntry($_.Uid.Split(“:”)[0].Split(“@”)[1])).HostName}}
$alltemplates|Export-Csv -Path "C:\My Data\CSV Output\$($CurrentDate)-first5templateswindows.csv" -NoTypeInformation -NoClobber
foreach($singletemplate in $alltemplates){
Write-Host "Marking Template Name $($singletemplate.Name) to VM"
Set-Template -Template $singletemplate.Name -ToVM -Confirm:$false |fl
$templatevm= Get-VM $singletemplate.Name
Write-Host "Collecting DHCP PortGroup Name for Vlanid 2067 from VMhost $($templatevm.VMHost)"
$dhcpportgroup=Get-VirtualPortGroup -VMHost $templatevm.VMHost |?{$_.ExtensionData.config.DefaultPortConfig.Vlan.VlanId -eq '2067'}
Write-Host "Collecting Network Adapter for $($templatevm.Name)"
$nic=Get-NetworkAdapter -VM $templatevm.Name
Write-Host "Adding Network Adapter to VM $($templatevm.Name) if not Present"
if($nic -eq $null){
New-NetworkAdapter -VM $templatevm.Name -Portgroup $dhcpportgroup -Type Vmxnet3 -StartConnected -Confirm:$false
}
else{
Write-Host "Changing Portgroup to $($dhcpportgroup.Name) to VM $($templatevm.Name)"
Get-NetworkAdapter -VM $templatevm.Name |Set-NetworkAdapter -Portgroup $dhcpportgroup -Confirm:$false |fl
}
Write-Host "Starting VM $($templatevm.Name) and wait in loop till GuestOperationsReady is true "
Start-VM -VM $templatevm.Name -Confirm:$false |fl
while($templatevm.ExtensionData.Guest.GuestOperationsReady -ne "True"){
Start-Sleep -Seconds 3
$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
}
Write-Host "Updating vmtools on $($templatevm.Name) if they are Outdated"
if($templatevm.ExtensionData.guest.toolsversionstatus -eq 'guestToolsNeedUpgrade'){
$timeoutSeconds = 900
$start = (Get-Date)
$task = Get-View -Id (Update-Tools -VM $templatevm.Name -NoReboot -RunAsync).Id
while((New-TimeSpan -Start $start -End (Get-Date)).TotalSeconds -lt $timeoutSeconds -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::running -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::queued){
Sleep 5
$task.UpdateViewData()
}
if($task.Info.State -eq [VMware.Vim.TaskInfoState]::running){
$task.CancelTask()
}
elseif($task.Info.State -eq [VMware.Vim.TaskInfoState]::error){
Write-Error "Update Tools failed"
}
}
Write-Host "Waiting for GuestOperationsReady to be true on $($templatevm.Name)"
$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
while($templatevm.ExtensionData.Guest.GuestOperationsReady -ne "True"){
Start-Sleep -Seconds 3
$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
}
Write-Host "Performing Invoke Operation on $($templatevm.Name)"
$sInvoke = @{
VM = $templatevm.Name
GuestUser = 'administrator'
GuestPassword = ''
ScriptText = $script
ScriptType = 'Powershell'
RunAsync = $true
Confirm = $false
}
$tasks += @{
VM = $templatevm.Name
Task = Invoke-VMScript @sInvoke
}
}
Write-Host "Invoke Operation is performed on all the templates and waiting for results to be collected"
while($tasks.Task.State -contains 'Running'){
sleep 2
}
$report=@()
$csvFiles = @()
foreach ($task in $tasks) {
$vm=Get-VM -Name $task.VM
Write-Host "Stopping VM $($vm.Name) to Apply windows updates"
Stop-VMGuest -VM $vm.Name -Confirm:$false
while($vm.ExtensionData.Runtime.PowerState -ne 'poweredOff'){
Start-Sleep -Seconds 1
$vm.ExtensionData.UpdateViewData("Runtime.Powerstate")
}
Write-Host "Starting back the VM $($vm.Name) after applying updates"
Start-VM -VM $vm.Name -Confirm:$false
$vm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
while($vm.ExtensionData.Guest.GuestOperationsReady -ne "True"){
Start-Sleep -Seconds 1
$vm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")
}
Write-Host "Performing Stop operation on VM $($vm.Name) before converting to Template"
Stop-VMGuest -VM $vm.Name -Confirm:$false
$vm.ExtensionData.UpdateViewData("Runtime.PowerState")
while($vm.ExtensionData.Runtime.PowerState -eq 'poweredOn'){
Start-Sleep -Seconds 1
$vm.ExtensionData.UpdateViewData("Runtime.Powerstate")
}
Write-Host "Updating report to csv"
$report+= $task | Select @{N='VM';E={$_.VM}},
@{N='State';E={$_.Task.State}},
@{N='Error';E={$_.Task.TerminatingError.Message}},
@{N ='Result'; E={$_.Task.Result.ScriptOutput.Split("`n") |Where-Object { $_ -ne '' } | %{$_.Trim("`r`n")}}}
}
$filename = "C:\AllTemplatepatchstatusreport.csv as on dated $($CurrentDate).csv"
$csvFiles += $filename
$report |Export-Csv -Path $filename -NoTypeInformation -NoClobber -UseCulture
Write-Host "Converting Back to templates"
$alltemplates |ForEach-Object -Process {
Get-NetworkAdapter -VM $_.name |Set-NetworkAdapter -NetworkName $_.Portgroup -Confirm:$false
Set-VM -VM $_.Name -ToTemplate -Confirm:$false
}
Stop-Transcript
$csvFiles+=$logfilelocation
Send-MailMessage -From "" -To "" -Subject "Script POC Template Patching" ` -Body "The attachment contains templates patching status" ` -Attachments $csvFiles -SmtpServer ''
However after completing the $timeoutSeconds = 900 it showed this error:
I'm wondering if this might be related to the difference between a Client Side Task and a Server Side Task?
Can you add some additional debugging lines around that part of the script?
Write-Host "Task type $($task.GetType().Name)"
$task.Info | Format-Custom
while((New-TimeSpan -Start $start -End (Get-Date)).TotalSeconds -lt $timeoutSeconds -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::running -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::queued){
Sleep 5
Get-Variable -Name task
$task.UpdateViewData()
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
After adding the debugging lines. I got this in transcript file upon running on one template.
Updating vmtools on SEH04_Win2k8_r2_std_64bit if they are Outdated
WARNING: Automatic update of VMware tools is not fully supported for non-Windows OSs. Manual intervention might be required.
Task type Task
class TaskInfo
{
Key = task-975776
Task =
class ManagedObjectReference
{
Type = Task
Value = task-975776
}
Description =
Name = UpgradeTools_Task
DescriptionId = VirtualMachine.upgradeTools
Entity =
class ManagedObjectReference
{
Type = VirtualMachine
Value = vm-3657
}
EntityName = SEH04_Win2k8_r2_std_64bit
Locked =
State = running
Cancelled = False
Cancelable = False
Error =
Result =
Progress = 0
Reason =
class TaskReasonUser
{
UserName = CORP\username
}
QueueTime =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date = 7/23/2020 12:00:00 AM
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay = 00:00:00
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 10
Kind = Utc
Millisecond = 983
Minute = 38
Month = 7
Second = 29
Ticks = 637310975099836510
TimeOfDay =
class TimeSpan
{
Ticks = 383099836510
Days = 0
Hours = 10
Milliseconds = 983
Minutes = 38
Seconds = 29
TotalDays = 0.443402588553241
TotalHours = 10.6416621252778
TotalMilliseconds = 38309983.651
TotalMinutes = 638.499727516667
TotalSeconds = 38309.983651
}
Year = 2020
DateTime = Thursday, July 23, 2020 10:38:29 AM
}
StartTime =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date = 7/23/2020 12:00:00 AM
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay = 00:00:00
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 0
Kind = Utc
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 637310592000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2020
DateTime = Thursday, July 23, 2020 12:00:00 AM
}
Day = 23
DayOfWeek = Thursday
DayOfYear = 205
Hour = 10
Kind = Utc
Millisecond = 990
Minute = 38
Month = 7
Second = 29
Ticks = 637310975099901090
TimeOfDay =
class TimeSpan
{
Ticks = 383099901090
Days = 0
Hours = 10
Milliseconds = 990
Minutes = 38
Seconds = 29
TotalDays = 0.443402663298611
TotalHours = 10.6416639191667
TotalMilliseconds = 38309990.109
TotalMinutes = 638.49983515
TotalSeconds = 38309.990109
}
Year = 2020
DateTime = Thursday, July 23, 2020 10:38:29 AM
}
CompleteTime =
EventChainId = 685800000
ChangeTag =
ParentTaskKey =
RootTaskKey =
ActivationId =
LinkedView =
}
Name Value
---- -----
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
task VMware.Vim.Task
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.Task:task-975776' has already been deleted
or has not been completely created"
At C:\My Data\Working\windowsupdateprototypescript_Workingfinal04.ps1:106 char:1
+ $task.UpdateViewData()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Waiting for GuestOperationsReady to be true on SEH04_Win2k8_r2_std_64bit
Performing Invoke Operation on SEH04_Win2k8_r2_std_64bit
So it is a Server Side Task after all.
The issue seems to be caused by the Task object that is obsolete when the task ended.
Let me check if there is a way to add a test for that, before calling UpdateViewData.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok Thanks LucD.
One more thing I’m suspected after looking the below lines from transcript file.
VMware tools update task is completed and script is not going to next line until timeout is completed. which I showed on my previous reply with screenshot. So might be the task object got deleted. And it’s still trying to find it.
The object 'vim.Task:task-975776' has already been deleted or
has not been completely created"
I think I found what is happening.
The condition in the Where-clause is incorrect.
There are 2 conditions to stay inside the Where loop:
Instead of the -or, those conditions should be combined with an -and
while((New-TimeSpan -Start $start -End (Get-Date)).TotalSeconds -lt $timeoutSeconds -and
($task.Info.State -eq [VMware.Vim.TaskInfoState]::running -or
$task.Info.State -eq [VMware.Vim.TaskInfoState]::queued)){
Sleep 5
$task.UpdateViewData()
}
if($task.Info.State -eq [VMware.Vim.TaskInfoState]::running){
$task.CancelTask()
}
elseif($task.Info.State -eq [VMware.Vim.TaskInfoState]::error){
Write-Error "Update Tools failed"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry for late response. It worked after replacing the condition in where-clause.