Skip to main content

Feature Update Install (Reboot Pending Machines Validation)

Summary

The script runs on machines where the Feature Update Reboot Pending custom field is flagged after the execution of the Feature Update Install With Tracking task, signifying a pending reboot to finalize the Feature Pack Update. Subsequently, the script updates the Feature Update Install Failure custom field with the outcome for monitoring purposes.

The script compares the current operating system build with the latest available build before and after the upgrade, with the latest build requiring manual entry into the script. For any new releases, the build number must be manually set in the script at step 1 for Windows 11 and step 2 for Windows 10.

Image

Sample Run

Image

Image

Dependencies

Task - Feature Update Install With Tracking
Custom Field - Feature Update Install Failure
Custom Field - Feature Update Reboot Pending

Create Script

Create a new Script Editor style script in the system to implement this Task.

Image

Image

Name: Feature Update Install (Reboot Pending Machines Validation)
Description: Monitors computers with pending reboots where the Feature Update Install with Tracking script was run but not yet rebooted, verifying the success of the update.
Category: Patching

Image

Script

Start by adding a row. You can do this by clicking the Add Row button at the bottom of the script page.

Image

Row 1 Function: Set User Variable

Select the Set User Variable function.

Image Image

Image

Type Win11LatestBuild in the Variable Name field and 10.0.22631 in the Value field. 110.0.26100 is the latest available Feature build for Windows 11 at the moment. Click Save to create the Win11LatestBuild variable.

Image

Image

Row 2 Function: Set User Variable

Insert a new row by clicking the Add Row button.

Image

Select the Set User Variable function.

Image Image

Image

Type Win10LatestBuild in the Variable Name field and 10.0.19045 in the Value field. 10.0.19045 is the latest available Feature build for Windows 10 at the moment. Click Save to create the Win10LatestBuild variable.

Image

Image

Row 3 Function: PowerShell Script

Insert a new row by clicking the Add Row button.

Image

Select the PowerShell Script function.

Image

Image

Image

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

$ProgressPreference = 'SilentlyContinue'
[Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([Net.SecurityProtocolType], 3072)
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
try {
Update-Module -Name PendingReboot -ErrorAction Stop
} catch {
Install-Module -Name PendingReboot -Repository PSGallery -SkipPublisherCheck -Force
Get-Module -Name PendingReboot -ListAvailable | Where-Object { $_.Version -ne (Get-InstalledModule -Name PendingReboot).Version } | ForEach-Object { Uninstall-Module -Name PendingReboot -MaximumVersion $_.Version }
}
Import-Module -Name PendingReboot 3>&1 2>&1 1>$null
if ((Test-PendingReboot -WarningAction SilentlyContinue).IsRebootPending) { return 'Still Reboot Pending'} else {return 'Good to Proceed'}

Image

Mark the Continue on Failure checkbox.

Image

Row 4 Logic: If Then

Insert a new If/Then logic from the Add Logic dropdown menu.

Image
Image

Row 4a Condition: Output Contains

Type Good to Proceed in the Value box and press Enter.
Image

Row 4b Function: Set Custom Field

Insert a new row by clicking the Add Row button inside the If Then logic.

Image

Image

Search and select the Set Custom Field function in the new row.

Image

Image

Search and select the Feature Update Reboot Pending custom field.
Image

Type False in the Value box and click the Save button.
Image
Image

Step 4c Function: PowerShell Script

Insert a new row by clicking the Add Row button inside the If Then logic.
Image

Image

Search and select the PowerShell Script in the newly added row.
Image

Image

Image

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

$osinfo = Get-CimInstance -ClassName Win32_OperatingSystem
if ( $osinfo.buildnumber -ge '20000' ) { [Version]$osinfo.version -ge [Version]'@Win11LatestBuild@' } else { [Version]$osinfo.Version -ge [Version]'@Win10LatestBuild@' }

Image

Mark the Continue on Failure checkbox.

Image

Image

Step 4d Logic: If Then

Insert a new If/Then logic inside the external If Then logic from the Add Logic dropdown menu.

Image

Image

Step 4d(i) Condition: Output Contains

Type False in the Value box and press Enter.
Image

Row 4d(ii) Function: Set Custom Field

Insert a new row by clicking the Add Row button inside the internal If Then logic.

Image

Image

Search and select the Set Custom Field function in the new row.

Image

Image

Search and select the Feature Update Install Failure custom field.
Image

Type Installation Failure/Error in the Value box and click the Save button.
Image

Image

Row 4d(iii) Function: Script Exit

Insert a new row by clicking the Add Row button inside the internal If Then logic.
Image

Image

Search and select the Script Exit function in the new row.
Image

Type Script Failed to install the latest available feature update. in the Error Message field and click the Save button.
Image

Image

Image

Step 4e Logic: If Then

Insert a new If/Then logic inside the external If Then logic from the Add Logic dropdown menu.

Image

Image

Step 4e(i) Condition: Output Contains

Type True in the Value box and press Enter.
Image

Row 4e(ii) Function: Set Custom Field

Insert a new row by clicking the Add Row button inside the internal If Then logic.

Image

Image

Search and select the Set Custom Field function in the new row.

Image

Image

Search and select the Feature Update Install Failure custom field.
Image

Type in the Value box and click the Save button. (There is a single space in the Value field.)
Image

Image

Click the Save button to save the Task.
Image

Completed Script

Image

Image

Image

Deployment

  • Go to Automation > Tasks.

  • Search for Feature Update Install (Reboot Pending Machines Validation) task.

  • Select the concerned task.

  • Click on the Schedule button to schedule the task/script.
    Image

  • This screen will appear.
    Image

  • Click the Does not repeat button.
    Image

  • This pop-up box will appear.
    Image

  • Click the OK button to run the task once per day.
    Image

  • Select the relevant time to execute the script. It is suggested to run this task during working hours, when most of the workstations are online.
    Image

  • Search and select the Windows Feature Pack Update: Reboot Pending group in the Resources.
    Image

  • Clicking the Run button will initiate the schedule.
    Image

  • The task will start appearing in the Scheduled Tasks.
    Image
    Image

  • The Suspend option can be used to suspend/stop the schedule.
    Image
    Image

Output

  • Custom Field