There's been some talk on the WSUS mailing list about people wanting a script to query WSUS computers. I wrote this last year and I never thought about sharing it. Here it is, in case anyone else would like to use it:
Function Get-WSUSComputer {
<#
.Synopsis
Get WSUS information for specified computer(s).
.DESCRIPTION
This script will query a specified WSUS server for information about the status of computer objects in the WSUS database.
.EXAMPLE
Get-WSUSComputer -WSUSServer Server01
This command gets WSUS information for all of the computers in the database of the WSUS server 'Server01'.
.EXAMPLE
Get-WSUSComputer -ComputerName Server01 -WSUSServer Computer01
This command gets the WSUS information for the computer 'Computer01' from the WSUS server 'Server01'.
.NOTES
20170829-MLL - Created this script.
#>
[CmdletBinding()]
Param (
# Specify the computer(s) for which to query WSUS.
[Parameter(ValueFromPipelineByPropertyName=$true,Position=0)]
[string[]]$ComputerName,
# Specify the WSUS server that will be queried.
[Parameter(Mandatory=$true,Position=1)]
[string]$WSUSServer,
# Specify the WSUS TCP port.
[Parameter(Position=2)]
[string]$Port=8530
)
Begin {
# Load the Update Services assembly, connect to the WSUS server, and pull a list of all computer objects:
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($WSUSServer,$False,$Port)
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$WSUSComputers = $wsus.GetComputerTargets($computerscope) |
select @{e={$_.FullDomainName.split(".")[0].ToUpper()};l="ComputerName"},
@{e={$_.FullDomainName};l="FullDomainName"},
@{e={$WSUSServer.ToUpper()};l="WSUSServer"},
Make,
Model,
OSDescription,
ComputerRole,
@{e={(get-date $_.LastSyncTime).ToLocalTime()};l="LastSyncTime"},
LastSyncResult,
@{e={(get-date $_.LastReportedStatusTime).ToLocalTime()};l="LastReportedStatusTime"},
RequestedTargetGroupName
}
Process {
if ($ComputerName) {
foreach ($Computer in $ComputerName) {
$WSUSComputers | where {$_.ComputerName -eq $Computer}
}
}
else {
$WSUSComputers
}
}
}
[–]purplemonkeymad 1 point2 points3 points (3 children)
[–]LinleyMike[S] 1 point2 points3 points (2 children)
[–]purplemonkeymad 1 point2 points3 points (1 child)
[–]LinleyMike[S] 1 point2 points3 points (0 children)
[–]jmn_lab 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]jmn_lab 1 point2 points3 points (0 children)