Skip to main content

Reboot Pending Check Automation

Summary

This task is designed to automatically detect the reboot pending status on endpoints and check the custom field Auto_RebootPendingCheck so that the agent gets added to the dynamic group Reboot Prompter Deployment - Auto.

Dependencies

Sample Run

Sample Run 1

Sample Run 2

Implementation

Create Task

Reboot Pending Check Automation
To implement this script, please create a new "PowerShell" style script in the system.

Create Task

  • Name: Reboot Pending Check Automation
  • Description: This script imports the module 'PendingReboot' to detect the pending status on the endpoints. Based on the output, it sets the custom field 'Auto_RebootPendingCheck'.
  • Category: Custom

Task Details

Script

Start by creating three separate rows. You can do this by clicking the "Add Row" button at the bottom of the script page.

Add Rows

Row 1: Function: Script Log

Row 1 Log

Paste the highlighted text:

Executing a PowerShell to validate the PowerShell version greater than 3.0.
If yes, install below modules:
PowerShellGet
PendingReboot

Row 1 Log Continued

Row 2: Function: PowerShell Script

Row 2 PowerShell

Row 2 PowerShell Continued

Paste in the following PowerShell script and set the expected time of script execution to 900 seconds.

# Check PowerShell version
if ($PSVersionTable.PSVersion.Major -lt 3) {
Write-Output "PowerShell version is not supported. Please upgrade to version 3.0 or higher."
Exit
}
# Check if the module is installed
if (-not (Get-Module -ListAvailable -Name PendingReboot)) {
Write-Output "Module not found. Installing..."
Install-Module -Name PendingReboot -Force
# Re-validate if the module is installed
if (Get-Module -ListAvailable -Name PendingReboot) {
Write-Output "Module installed successfully."
} else {
Write-Output "Module installation failed."
Exit
}
} else {
Write-Output "Module already installed."
}

Row 3: Function: Script Log

Row 3 Log

In the script log message, simply type %output% so that the script will send the results of the PowerShell script above to the output on the Automation tab for the target device.

Row 3 Log Continued

Row 4: Logic: If/Then/Else

Row 4 Logic

Row 4 Logic Continued

Row 4a: Condition: Output Contains

In the IF part, enter Module installed successfully in the right box of the "Output Contains" part.

Row 4a Condition

Row 4b: Function: PowerShell Script

Add a new row by clicking on the Add Row button.

Row 4b PowerShell

Row 4b PowerShell Continued

Paste in the following PowerShell script and set the expected time of script execution to 300 seconds.

(Test-PendingReboot -SkipConfigurationManagerClientCheck).IsRebootPending

Row 4c: Function: Script Log

Row 4c Log

In the script log message, simply type The Pending Reboot Requirement: %output% so that the script will send the results of the PowerShell script above to the output on the Automation tab for the target device.

Row 4c Log Continued

Row 4c.1: Logic: If/Then

Row 4c.1 Logic

Row 4c.1 Logic Continued

Row 4c.2: Condition: Output Contains

In the IF part, enter True in the right box of the Output Contains part.

Row 4c.2 Condition

Row 4c.3: Function: Set Custom Field

Add a new row by clicking on the Add row button.

Select Function Set Custom Field. When you select set custom field, it will open up a new window.

In this window, search for the Auto_RebootPendingCheck field.

  • Custom Field: Auto_RebootPendingCheck
  • Value: True

Row 4c.3 Set Custom Field

Row 4d: Function: Script Exit

Add a new row by clicking on the Add row button.

Row 4d Exit

In the script exit message, leave it blank.

Row 4d Exit Continued

Row 4e: Condition: Script Exit

Add a new row in the Else section and select Script Exit.

In the script exit message, simply type %output%.

Row 4e Exit

Row 5: Complete

Row 5 Complete

Deployment

It is suggested to run the Task every 2 hours against the group Dynamic Group - Automatic Reboot Pending Check.

  • Go to Automation > Tasks.
  • Search for Reboot Pending Check Automation Task.
  • Select the concerned task.
  • Click on the Schedule button to schedule the task/script.

Schedule Task

This screen will appear.

Schedule Task Continue

Select the relevant time to run the script and click the Do not repeat button.

Schedule Task Time

A pop-up box will appear.

Change the number of hours to 2 and click OK.

Change Hours

Select the target to schedule the 'Force Reboot Server With Reboot Windows Verification'.

Select Target

Now click the Run button once all customization is set to initiate the task.

Run Task

The task will start appearing in the Scheduled Tasks.

Output

  • Task log