WSUS – list computers needing a restart

Prerequisites – Must have a WSUS management tools installed on the computer that you are running this script,

[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration“)
$updateServer = “WSUS SERVER NAME or IP Address“
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$false)
$computerScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope;
$computerScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
$updateScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
$computers = $wsus.GetComputerTargets($computerScope);

$computers | select FullDomainName,IPaddress | Sort-Object -Property IPaddress
$count = $computers | Measure-Object;

Write-host "";
write-host "Total number of objects: "$count.count;

Change the $updateServer to you WSUS server name or IP address.

PowerShell script to approve WSUS updates

Here is a short script that is very useful to approve missing updates for a specific server:

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

$updateServer = “WSUS.server.IP.address“

$machineName = Read-Host “enter DNS name of the computer you wish to approve updates for“

$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$false)

$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope

$updateScope.includedInstallationStates = “NotInstalled“

$com = $wsus.GetComputerTargetByName($machineName)

$groupname =  Read-Host “Enter target WSUS group name”
$Target = $wsus.GetComputerTargetGroups() | where {$_.Name -eq $groupname}

$action = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install

$updates = $com.GetUpdateInstallationInfoPerUpdate($updateScope)
$updates | foreach-object {$uid = $_.UpdateId; $u = $wsus.GetUpdate($uid); $u.Title; $u.Approve($action,$target);}

WSUS – approving multiple updates for a specific computer

Very useful script:

Get-ComputerTargetGroups.ps1
[void][reflection.assembly]::LoadWithPartialName(Microsoft.UpdateServices.Administration)
$updateServer = WSUSServername
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$false)

$wsus.GetComputerTargetGroups()

ApproveMultipleUpdates.ps1
[void][reflection.assembly]::LoadWithPartialName(Microsoft.UpdateServices.Administration)
$updateServer = WSUSServername
$machineName = Read-Host Please enter the full DNS name of the computer you wish to approve updates for

$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$false)
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope
$updateScope.includedInstallationStates = NotInstalled
$com = $wsus.GetComputerTargetByName($machineName)

$groupid= Read-Host Please enter the Computer Group Target ID

$group = $wsus.GetComputerTargetGroup($groupid)
$action = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install

$updates = $com.GetUpdateInstallationInfoPerUpdate($updateScope)
$updates | foreach-object {$uid = $_.UpdateId; $u = $wsus.GetUpdate($uid); $u.Title; $u.Approve($action,$group);}



original post here:
http://www.jonathanmedd.net/2008/11/wsus-30-approving-multiple-updates-for-a-specific-computer-with-powershell.html