Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

Force WSUS checkin with Powershell

This little script will start the wuauserv service if it’s stopped and for a WSUS check-in. I’ve tested the script on Windows Server 2K8 and 2K8 R2 and on Windows 7 and it works fine.

All that said, THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK.

Here is the code:

#  *** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ***
#
# Author: David Hall, signalwarrant.com
#
# This script will allow you to start the wuauserv service and force a WSUS checkin.

# Define a service variable
$service = get-service -Name wuauserv

# Check to see if the service variable is stopped
if ($service.Status -eq "Stopped"){

    # If the service is stopped we're going to start it and force WSUS checkin
    # and Exit
    Write-host -foregroundcolor Cyan "1. WUAUSERV is stopped... starting"
    Start-Service wuauserv 
        [System.Threading.Thread]::Sleep(1500)
    Write-host -foregroundcolor Cyan "2. WUAUSERV started"    
        [System.Threading.Thread]::Sleep(1500)
    Write-host -foregroundcolor Cyan "3. Forcing WSUS Checkin"
    Invoke-Command {wuauclt.exe /detectnow}
        [System.Threading.Thread]::Sleep(1500)
    Write-host -foregroundcolor Cyan "4. Checkin Complete"
    Exit  

    } else {

    # If the service is started we'll just for the WSUS checkin and Exit
    Write-host -foregroundcolor Cyan "1. Forcing WSUS Checkin"
    Invoke-Command {wuauclt.exe /detectnow}
        [System.Threading.Thread]::Sleep(1500)
    Write-host -foregroundcolor Cyan "2. Checkin Complete"
    Exit

    }

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.