vin01's Posts

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 V... See more...
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
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 too... See more...
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:
Ok I will give a try and update here
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 t... See more...
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:
Thanks Its working
while((New-TimeSpan -Start $start -End (Get-Data)).TotalSeconds -lt $timeoutSeconds -or Its Get-Date right?
I will give a try and update
Hi LucD With your help I have completed the below script. Thanks for support. The script needs few improvements which I noticed when running on multiple vcenters separately.I am trying to red... See more...
Hi LucD With your help I have completed the below script. Thanks for support. The script needs few improvements which I noticed when running on multiple vcenters separately.I am trying to reduce errors if I run on multiple environments. 1.On few vms Update-Tools will never completes and the whole script will struck on that line. However I can see vmware tools are in running state but still update will not succeed. Suspected issue inside the guest os but  if I do manually it installed without any issue. So is there anyway to keep a wait time for 30mins and if still update-tools is not completed then stop that operation and Dismount-Tools the tools and proceed with next lines. 2.with few vms Stop-VMGuest is will not succeed with first attempt.(Not the same vms where Update-Tools failed) For example in the below output for one vm. The Stop-VMGuest operation issued from script is failed but when I do a guest shutdown from the vcenter it succeeded. So my thought is to include Stop-VMGuest  3 times with a wait time of 5mins. Like  Stop-VMGuest and wait for 5mins and if the 1st operation fails then try again stop-vmguest operation and if all 3 attempts failed then do stop-vm. $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=@() $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 5  |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'} 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'){ Update-Tools -VM $templatevm.Name -NoReboot } 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") } 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") } $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 'internalmail.sweng.ncr.com' $alltemplates |ForEach-Object -Process { Get-NetworkAdapter -VM $_.name |Set-NetworkAdapter -NetworkName $_.Portgroup -Confirm:$false Set-VM -VM $_.Name -ToTemplate -Confirm:$false } Stop-Transcript
Ok Thanks
Yes Thanks now its  working with this version, One last question for this thread Is it possible to capture failed and success output using wait-task because based on your last reply for my othe... See more...
Yes Thanks now its  working with this version, One last question for this thread Is it possible to capture failed and success output using wait-task because based on your last reply for my other thread(Same output is displayed multiple times ) I have created the script which I posed as question in this thread. Why I am wait-task is because the execution is very fast.
But if I execute for that same VM as below I got the result. Invoke-VMScript -VM $singlevm -ScriptText $script -ScriptType Powershell -GuestUser 'administrator' -GuestPassword ''
Some issue. I am not getting the output. Below is the output. For the same VM if I execute as below I can see the output.
Its not displaying any output for vms when authentication is success. When authentication fails its writing the output. I am also thinking instead of Write-Output can we keep it in one... See more...
Its not displaying any output for vms when authentication is success. When authentication fails its writing the output. I am also thinking instead of Write-Output can we keep it in one variable for both failure and success machines so that I can export to csv.
Yes LucD by using your last script I used try catch method now but its not giving any results.  How to use with -RunAsync switch and Wait-Task -Task $tasks because I need to run on large set of v... See more...
Yes LucD by using your last script I used try catch method now but its not giving any results.  How to use with -RunAsync switch and Wait-Task -Task $tasks because I need to run on large set of vms and with -RunAsync will give results more quicker. $script = @' $output=Get-Service |select Name $output.Name -join ',' '@ $tasks = @() foreach($singlevm in Get-VM 'Win2k16_Std_64bit-testClone'){ try {     $sInvoke = @{         VM            = $singlevm.Name         GuestUser     = 'administrator'         GuestPassword = 'password'         ScriptText    = $script         ScriptType    = 'Powershell'         ErrorAction   = 'Stop'     }     $tasks+=Invoke-VMScript @sInvoke  -RunAsync -Confirm:$false     break     }     catch {     } } Wait-Task -Task $tasks -Verbose $report=foreach ($task in $tasks) { '' | Select-Object @{N='VM';E={$task.Result.VM.Name}}, @{N ='Result'; E={$task.Result.ScriptOutput.Split("`n") |Where-Object { $_ -ne '' } | %{$_.Trim("`r`n")}}} } $report
If you run without the RunAsync switch there is no Task returned by Invoke-VMScript. I just tested for one vm for which credentials are wrong. For that error is not written in $tasks. It’s just ... See more...
If you run without the RunAsync switch there is no Task returned by Invoke-VMScript. I just tested for one vm for which credentials are wrong. For that error is not written in $tasks. It’s just showed up in PowerShell console which I showed in above snap. But the result that you show seems to indicate that the supplied credentials are not correct for at least one of the targetted VMs. Yeah I intentionally give wrong credentials to show you.
If I run like this nothing is captured in $tasks $script = @' $output=Get-Service |select Name $output.Name -join ',' '@ $tasks = @() foreach($singlevm in Get-VM 'Win2k16_Std_64bit-tes... See more...
If I run like this nothing is captured in $tasks $script = @' $output=Get-Service |select Name $output.Name -join ',' '@ $tasks = @() foreach($singlevm in Get-VM 'Win2k16_Std_64bit-testClone'){     $sInvoke = @{         VM            = $singlevm.Name         GuestUser     = 'administrator'         GuestPassword = 'password'         ScriptText    = $script         ScriptType    = 'Powershell'         ErrorAction   = 'Stop'     }     $tasks+=Invoke-VMScript @sInvoke     #-RunAsync -Confirm:$false }
I am using below script to get service information from the windows guest os using invoke-vmscript but for few vms the credentials which i provided in the script are not valid so for those vms i ... See more...
I am using below script to get service information from the windows guest os using invoke-vmscript but for few vms the credentials which i provided in the script are not valid so for those vms i am not getting any error output or vmname with blank result in output $report. So is it possible to write the error output while using wait-task because when I look at the powershell console the wait-task is displaying the error 'Failed to authenticate with the guest operating system using the supplied credentials' but in the $task.Result.ScriptOutput is not showing up the  authentication failed error and even $task.Result.VM.Name is not showing up the vm name. I am ok for few vms if authentication failed or any other error but expecting to write that error in $report for those vmnames. $script = @' $output=Get-Service |select Name $output.Name -join ',' '@ $tasks = @() foreach($singlevm in Get-VM test01,test02,test03,test04,test05,test06,test07){     $sInvoke = @{         VM            = $singlevm.Name         GuestUser     = 'administrator'         GuestPassword = 'password'         ScriptText    = $script         ScriptType    = 'Powershell'         ErrorAction   = 'Stop'     }     $tasks+=Invoke-VMScript @sInvoke -RunAsync -Confirm:$false } Wait-Task -Task $tasks -Verbose $report=foreach ($task in $tasks) { '' | Select-Object @{N='VM';E={$task.Result.VM.Name}}, @{N ='Result'; E={$task.Result.ScriptOutput.Split("`n") |Where-Object { $_ -ne '' } | %{$_.Trim("`r`n")}}} } $report
Thanks Working Now.
I have tested like this but its failing to do stop again. I think ExtensionData.UpdateViewData is not updating Guest.GuestOperationsReady value. Anything wrong in this lines. $vm=Get-VM -Name ... See more...
I have tested like this but its failing to do stop again. I think ExtensionData.UpdateViewData is not updating Guest.GuestOperationsReady value. Anything wrong in this lines. $vm=Get-VM -Name 'Win2k16_Std_64bit-testClone' Stop-VMGuest -VM $vm.Name -Confirm:$false while($vm.ExtensionData.Runtime.PowerState -eq 'poweredOn'){     Start-Sleep -Seconds 1     $vm.ExtensionData.UpdateViewData("Runtime.Powerstate") } Start-VM -VM $vm.Name -Confirm:$false while($vm.ExtensionData.Guest.GuestOperationsReady -ne "True"){     Start-Sleep -Seconds 1     $vm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady") } Stop-VMGuest -VM $vm.Name -Confirm:$false while($vm.ExtensionData.Runtime.PowerState -eq 'poweredOn'){     Start-Sleep -Seconds 1     $vm.ExtensionData.UpdateViewData("Runtime.Powerstate") } Get-VM $vm.Name | Select Name,Powerstate
Actually my original intention of using  Restart-VMGuest is on the template vms which I am going to execute are pending restart for windows updates. So I am trying to restart and let the windows ... See more...
Actually my original intention of using  Restart-VMGuest is on the template vms which I am going to execute are pending restart for windows updates. So I am trying to restart and let the windows apply the patches and start the machine back. Once the machine start back and GuestOperationsRead is $true then I will do the guest stop. I am not sure Stop-VMGuest will work on this scenario. Will it work if I do Stop-VMGuest and start it back?