Out of Date Cumulative Update (Post Reboot Verification)
Summary
This task validates whether the Cumulative Update installed by the Out of Date Cumulative Update (Autofix) task succeeded post-reboot.
Sample Run
Dependencies
- Custom Field - EndPoint - Out_of_Date_CU_Autofix_Result
- Custom Field - EndPoint - Out_of_Date_CU_Autofix_Date
- Device Group - Out of Date CU _ Reboot Pending
- Task - Out of Date Cumulative Update (Autofix)
Variables
Name | Description |
---|---|
TaskRunTime | Value stored in the EndPoint - Out_of_Date_CU_Autofix_Date Custom Field. |
Output | Output of the previously executed PowerShell script. |
Task Creation
Create a new Script Editor
style script in the system to implement this Task.
Name: Out of Date Cumulative Update (Post Reboot Verification)
Description: This task validates whether the Cumulative Update installed by the Out of Date Cumulative Update (Autofix) task succeeded post-reboot.
Category: Patching
Task
Navigate to the Script Editor section and start by adding a row. You can do this by clicking the Add Row
button at the bottom of the script page.
A blank function will appear.
Row 1 Function: Set Pre-defined Variable
Search and select the Set Pre-defined Variable
function.
The following function will pop up on the screen:
- Type
TaskRunTime
in theVariable Name
field. - Select the
Custom Field
radio button. - Search and select the company-level
Out_of_Date_CU_Autofix_Date
custom field in theSearch Custom Field
field. - Click the
Save
button to save the changes.
Row 2 Function: PowerShell Script
Add a new row by clicking on the Add Row
button.
A blank function will appear.
Search and select the PowerShell Script
function.
The following function will pop up on the screen:
Paste in the following PowerShell script and leave the expected time of script execution to 300
seconds. Click the Save
button.
$TaskRunTime = '@TaskRunTime@'
if ( $TaskRunTime -eq '0001-01-01 00:00:00' ) {
return 'Exit'
} else {
$Uptime = ( systeminfo | Find 'System Boot Time' )
if ( $Uptime -match '([0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}, [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})' ) {
$uptime = $Matches[1]
}
$uptime = $uptime -replace '\/', '-' -replace ',', ''
if ( [DateTime]$uptime -ge [DateTime]$TaskRunTime ) {
return 'Rebooted'
} else {
return 'Still Pending'
}
}
Row 3 Logic: If/Then/Else
Row 3a Condition: Output Does Not Contain
Change the comparator to Does Not Contain
.
Type Rebooted
in the Input Value or Variable
field and press Enter
.
Row 3b Function: Script Log
Add a new row by clicking the Add Row
button inside the If
section.
A blank function will appear.
Search and select the Script Log
function in the newly appeared row.
The following function will pop up on the screen:
Type Still reboot pending
in the Script Log Message
field and click the Save
button.
Row 3c Function: Script Exit
Click the Add Row
button inside the If
section.
Search and select the Script Exit
function in the newly appeared row.
The following function will pop up on the screen:
Click the Save
button without typing anything in the Error Message
field.
Row 3d Script: Cumulative Update Audit
Click the Add Row
button in the Else
section.
Change the Function
to Script
from the dropdown.
Search and select the Cumulative Update Audit
script.
Row 3e Logic: If/Then/Else
Add a new If/Then/Else
logic inside the Else
section.
Row 3e(i) Condition: Custom Field Contains
Select the Custom Field
from the dropdown menu.
Search and select the Latest Cumulative Update
custom field and type Failed
in the comparator and press Enter
.
Row 3e(ii) Function: Set Custom Field
Add a new row by clicking the Add Row
button inside the If
section.
Search and select the Set Custom Field
function.
Search and select Out_of_Date_CU_Autofix_Result
in the Search Custom Field
field and set Failed
in the Value
field and click the Save
button.
Row 3e(iii) Function: Script Exit
Click the Add Row
button inside the If/Then
logic.
Search and select the Script Exit
function in the newly appeared row.
The following function will pop up on the screen:
Paste the following lines in the Error Message
field and click the Save
button.
Cumulative Update Failed to install after restarting the computer as well.
Row 3e(iv) Function: Set Custom Field
Add a new row by clicking the Add Row
button inside the Else
section.
Search and select the Set Custom Field
function.
Search and select Out_of_Date_CU_Autofix_Result
in the Search Custom Field
field and set Installed
in the Value
field and click the Save
button.
Row 3e(v) Function: Set Custom Field
Add a new row by clicking the Add Row
button inside the Else
section.
Search and select the Set Custom Field
function.
Search and select Out_of_Date_CU_Autofix_Date
in the Search Custom Field
field and set 0001-01-01 00:00:00
in the Value
field and click the Save
button.
Click the Save
button at the top-right corner of the screen to save the script.
Completed Script
Deployment
It is suggested to run the task once per day against the Out of Date CU _ Reboot Pending device group.
- Go to
Automation
>Tasks.
- Search for
Out of Date Cumulative Update (Post Reboot Verification)
task. - Select the concerned task.
- Click on the
Schedule
button to schedule the task.
This screen will appear.
Click the Does not repeat
button.
This pop-up box will appear.
Click the OK
button without making any changes to set it to run once per day.
Recurrence will be updated to Every Day
.
Select the Device Groups
option in the Targeted Resources
section.
Search and select the Out of Date CU _ Reboot Pending device group.
Now click the Run
button to initiate the task.
The task will start appearing in the Scheduled Tasks.
Output
- Script Log
- Custom Field