Synchronize WSUS with Powershell

Yesterday, I showed you how to script the WSUS Cleanup Wizard with Powershell. Today, the WSUS fun continues! Here’s how to use powershell to “manually” synchronize your WSUS server, i.e. download the latest updates.

#Region VARIABLES
 
# WSUS Connection Parameters:
[String]$updateServer = "myWSUSServer.domain.local"
[Boolean]$useSecureConnection = $False
[Int32]$portNumber = 80
 
#EndRegion VARIABLES
 
#Region SCRIPT
 
# Load .NET assembly
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
 
# Connect to WSUS Server
$Wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$useSecureConnection,$portNumber)
 
# Perform Synchronization
$Subscription = $Wsus.GetSubscription()
$Subscription.StartSynchronization()
 
#EndRegion SCRIPT

Download the script here: Synchronize-Wsus (rename to .ps1)

Enjoy!
Hugo

»crosslinked«

5 thoughts on “Synchronize WSUS with Powershell”

  1. Hi,

    I am seeking a way to sync computer in WSUS with AD OUs but no luck, do you think to make one script for that?…I’d love too but it seem out of my capability.

    TIA.

  2. Hi Chairuou,
    I am not sure what you mean. If you configured GPO’s to assign computers to a specific WSUS group, the computers should automatically appear in the proper group in WSUS. You can force a computer to talk to WSUS by running: wuauclt /detectnow on the computer.
    Hugo

Leave a Reply