Automating WSUS via PowerShell

You can do it with PowerShell, but you need to have the WSUS administration console installed on the machine too.

You can then do the following.

[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")

$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(“wsus_server”,$False)

$wsus

You can then get a list of target groups with

$wsus.GetComputerTargetGroups()

Or select a group with

$targetgroup = $wsus.GetComputerTargetGroups() | ? {$_.Name -eq "some target name"}

There is much more information in Use PowerShell to Perform Basic Administrative Tasks on WSUS, but the above information will get you information on the groups.


As Drifter104 said, there isn't yet a PowerShell module available for managing WSUS, although one will be included in the next Windows Server release (https://technet.microsoft.com/en-us/library/hh826166.aspx); meanwhile, you need to import the .NET assembly for managing WSUS and use that; one of the greatest features in PowerShell is, even if it doesn't include native cmdlets for performing a given task, you have access to the full .NET enviroment from it, and you can actually do anything you would be able to do from a .NET application.

About the scripting part: once you get the names of your WSUS groups in an array, dinamically building the list shown to your users is quite easy; simply loop through the array and use an index for the selection number:

Write-Host Please select a Computer Group from the below options:

$i = 1

foreach($g in $TargetComputerGroups)
{
    Write-Host Press $i for $g
    $i++
}

$sel = Read-Host -Prompt "Enter selection: "