Out of Date Cumulative Update (Autofix)
Summary
Installs the latest available Cumulative Update on the machines where a CU has not been installed in the last 75 days.
Sample Run
Dependencies
- Custom Field - Company - Out_of_Date_CU_Autofix
- Custom Field - Site - Out_of_Date_CU_Autofix
- Custom Field - EndPoint - Out_of_Date_CU_Autofix
- Custom Field - EndPoint - Out_of_Date_CU_Autofix_Result
- Custom Field - EndPoint - Out_of_Date_CU_Autofix_Date
- Device Group - Out of Date CU _ Autofix Required
- Custom Fields - Reboot Prompter
Variables
Name | Description |
---|---|
Company_Selection | Value stored in the Company - Out_of_Date_CU_Autofix Custom Field. |
Site_Selection | Value stored in the Site - Out_of_Date_CU_Autofix Custom Field. |
Endpoint_Selection | Value stored in the EndPoint - Out_of_Date_CU_Autofix 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 (Autofix)
Description: Installs the latest available Cumulative Update on the machines where a CU has not been installed in the last 75 days.
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
Company_Selection
in theVariable Name
field. - Select the
Custom Field
radio button. - Search and select the company-level
Out_of_Date_CU_Autofix
Custom Field in theSearch Custom Field
field. - Click the
Save
button to save the changes.
Row 2 Function: Set Pre-defined Variable
Add a new row by clicking on the Add Row
button.
A blank function will appear.
Search and select the Set Pre-defined Variable
function.
The following function will pop up on the screen:
- Type
Site_Selection
in theVariable Name
field. - Select the
Custom Field
radio button. - Search and select the site-level
Out_of_Date_CU_Autofix
Custom Field in theSearch Custom Field
field. - Click the
Save
button to save the changes.
Row 3 Function: Set Pre-defined Variable
Add a new row by clicking on the Add Row
button.
A blank function will appear.
Search and select the Set Pre-defined Variable
function.
The following function will pop up on the screen:
- Type
Endpoint_Selection
in theVariable Name
field. - Select the
Custom Field
radio button. - Search and select the Endpoint-level
Out_of_Date_CU_Autofix
Custom Field in theSearch Custom Field
field. - Click the
Save
button to save the changes.
Row 4 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 the following PowerShell script and leave the expected time of script execution to 300
seconds. Click the Save
button.
$os = ( Get-CimInstance -ClassName Win32_OperatingSystem ).Caption
if ( '@EndPoint_Selection@' -eq 'Enable' ) {
'Enable'
} elseif ( '@EndPoint_Selection@' -eq 'Disable' ) {
'Disable'
} elseif ( $os -match 'Server' ) {
if ( '@Site_Selection@' -eq 'Enable for Server' ) {
'Enable'
} elseif ( '@Site_Selection@' -eq 'Disable for Server' ) {
'Disable'
} elseif ( '@Company_Selection@' -eq 'Servers as well' ) {
'Enable'
} else {
'Disable'
}
} elseif ( '@Site_Selection@' -eq 'Enable' ) {
'Enable'
} elseif ( '@Site_Selection@' -eq 'Disable' ) {
'Disable'
} elseif ( '@Company_Selection@' -eq 'Enable' ) {
'Enable'
} elseif ( '@Company_Selection@' -eq 'Disable' ) {
'Disable'
} else {
'Disable'
}
Row 5 Logic: If/Then
A blank function will appear.
Row 5a Condition: Output Contains
Type Disable
in the Input Value or Variable
field and press Enter
.
Row 5b Function: Script Log
Click the Add Row
button inside the If/Then
logic.
Search and select the Script Log
function in the newly appeared row.
The following function will pop up on the screen:
Type Autofix is disabled.
in the Script Log Message
field and click the Save
button.
Row 5c 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:
Click the Save
button without typing anything in the Error Message
field.
Row 6 Function: PowerShell Script
Add a new row by clicking on the Add Row
button outside the If/Then
logic.
A blank function will appear.
Search and select the PowerShell Script
function.
The following function will pop up on the screen:
Paste the following PowerShell script and set the expected time of script execution to 7200
seconds. Click the Save
button.
# Needs update to JSON format
Row 7 Logic: If/Then/Else
Row 7a Condition: Output Contains
Type Failed to Install
in the Input Value or Variable
field and press Enter
.
Row 7b 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, then click the Save
button.
Row 7c 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.
Script Failed.
Output: %Output%
Row 7d Logic: If/Then/Else
Add a new If/Then/Else
logic inside the Else
section.
Row 7d(i) Condition: Output Contains
Change the comparator to Does Not Contain
.
Type Successfully installed the latest available Cumulative Update
in the Input Value or Variable
field and press Enter
.
Row 7d(ii) Function: Script Log
Click the Add Row
button after the condition.
Search and select the Script Log
function in the newly appeared row.
The following function will pop up on the screen:
Type Script Result: %Output%
in the Script Log Message
field and click the Save
button.
Row 7d(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:
Click the Save
button without typing anything in the Error Message
field.
Row 7d(iv) Logic: If/Then/Else
Add a new If/Then/Else
logic inside the Else
section.
Row 7d(iv)1 Condition: Output Does Not Contain
Change the comparator to Does Not Contain
.
Type Successfully installed the latest available Cumulative Update
in the Input Value or Variable
field and press Enter
.
Row 7d(iv)2 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, then click the Save
button.
Row 7d(iv)3 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:
Paste the following lines in the Error Message
field and click the Save
button.
Script Failed.
Output: %Output%
Row 7d(iv)4 Function: Set Custom Field
Add a new row by clicking the Add Row
button inside the Else
section.
A blank function will appear.
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 Reboot Pending
in the Value
field, then click the Save
button.
Row 7d(iv)5 Function: PowerShell Script
Add a new row by clicking the Add Row
button inside the Else
section.
A blank function will appear.
Search and select the PowerShell Script
function.
The following function will pop up on the screen:
Paste the following PowerShell script and leave the expected time of script execution to 300
seconds. Click the Save
button.
(Get-Date).ToString('yyyy-MM-dd HH:mm:ss')
Row 7d(iv)6 Function: Set Custom Field
Add a new row by clicking the Add Row
button inside the Else
section.
A blank function will appear.
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 %Output%
in the Value
field, then click the Save
button.
Row 7d(iv)7 Function: PowerShell Script
Add a new row by clicking the Add Row
button inside the Else
section.
A blank function will appear.
Search and select the PowerShell Script
function.
The following function will pop up on the screen:
Paste the following PowerShell script and leave the expected time of script execution to 300
seconds. Click the Save
button.
$os = ( Get-CimInstance -ClassName Win32_OperatingSystem ).Caption;
if ( $os -match 'Server' ) {
'This is a Server Operating System. It should be restarted manually. Exiting the Script.'
} else {
'Initiating the reboot pending prompt solution on the machine.'
}
Row 7d(iv)8 Function: Script Log
Add a new row by clicking the Add Row
button inside the Else
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 %Output%
in the Script Log Message
field and click the Save
button.
Row 7d(v) Logic: If/Then
Add a new If/Then
logic inside the Else
section of the previous logic.
Row 7d(v)1 Condition: Custom Field Equal
Select the Custom Field
option from the DropDown
button.
Search and select the Out_of_Date_CU_Autofix_Result
custom field.
Change the operator to Equals
, type Reboot Pending
in the comparator and press Enter
.
Add another Condition by clicking the Add Condition
button.
Type Initiating the reboot pending prompt solution on the machine
in the Input value or variable
field and press Enter
.
Row 7d(v)2 Function: Set Custom Field
Add a new row by clicking the Add Row
button inside the Else
section.
A blank function will appear.
Search and select Set Custom Field
Function.
Search and select Prompter_RebootPending
in the Search Custom Field
field and set True
in the Value
field and click the Save
button.
Mark the Continue on Failure
Check-Box.
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 week against the Out of Date CU _ Autofix Required device group.
- Go to
Automation
>Tasks
. - Search for
Out of Date Cumulative Update (Autofix)
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.
- Change the Repeat interval to
Week(s)
, select an appropriate day; I have selectedMonday
in the attached screenshot. Click theOK
button to save the changes.
- Recurrence will be updated to
Every Week on \<Selected Weekday>
.
- Select the
Device Groups
option in theTargeted Resources
section.
- Search and Select the Out of Date CU _ Autofix Required 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