SCCM Script: GPUpdate (Silently) with Logging and Success and Failure Output

  • 5 June 2018
  • Sean Huggans
Description: 

This script is meant to be used as a "Script" in Configuration Manager. It will not cause the GPUpdate popup window for your users. The script will work in Windows 7,8/8.1, 10, 11, and should also work for Server OS as well.

Language: 
PowerShell
Usage Type: 
Standalone
Script Source: 
################################################################################################################################
# Run-GPUpdateSilentlyAsConsoleScript.ps1
# Script Auther: Sean Huggans
# Script Version 22.8.1.1
################################################################################################################################
# Variables
################
$LogDir = "C:\Temp\System Compliance"
$LogName = "GPUpdate"
$LogPath = "$($LogDir)\$($LogName).log"
 
###################
# Functions
###################
function Log-Action ($Message) {
    if (!(test-path -Path $LogDir)) {
        New-Item -ItemType Directory -Path $LogDir -Confirm:$false -Force | Out-Null
    }
    "[ $(Get-Date -Format 'yyyy.MM.dd HH:mm:ss') ] $($Message)" | Out-File -FilePath $LogPath -Force -Append
}
 
try {
    $JobName = "GPUpdate$PC-$(Get-Date -format "yyyyMMddHHmmss")"
    Start-Job -Name $JobName -ScriptBlock { & echo n | GPUpdate /Force /wait:0 } | Out-Null
    $count = 60
 
    do {
        switch ($(Get-Job -Name $JobName).State) {
            "Running" {
                Start-Sleep -Seconds 1
            }
            "Completed" {
                Log-Action "GPUpdate Invoked."
                Remove-job -Name $JobName -Confirm:$false -Force -erroraction SilentlyContinue
                return "Success"
            }
            "Failed" {
                Remove-job -Name $JobName -Confirm:$false -Force -erroraction SilentlyContinue
                return "Failed (GPUpdate Failed)"
            }
        }
        $count -=1
    } until ($count -le 0)
    Remove-job -Name $JobName -Confirm:$false -Force -erroraction SilentlyContinue
    return "Failed (Time Exceeded 60 Seconds)"
} catch {
    Log-Action "Invoking GPUpdate Failed."
    return "Failure (Starting Job)"
}
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.