Retrieve PC make and model info from WSUS

I came across a scenario where I needed to get the make and model of all of the client systems in my environment for reporting.  There are a few routes that I could take to retrieve this information (Inventory, WSUS, AV), and after briefly checking over each of them, it looked like WSUS was kept the most up-to-date for my purposes.


$Server = "wsusservername"
$Results = "C:\wsusmodels.csv"

[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") |
out-null

$WSUS = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($Server,$False)

$computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computers = $WSUS.GetComputerTargets($computerScope)
 
$Computers | 
Sort-Object Model |
Select-Object fulldomainname,ipaddress,make,model |
Export-CSV -Path $Results -NoTypeInformation

At the beginning of the script, we set some variables to determine the WSUS server that we will be connecting to and the location where we want to output the results.  We then load the assemblies for WSUS and connect to the server.

[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") |
out-null
$WSUS = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($Server,$False)

Once connected to the server, we need to create a computer target scope and then query a list of all computers in that scope.


$computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computers = $WSUS.GetComputerTargets($computerScope)

Now that we have a list of computer objects in the $Computers variable, we want to sort the objects based on the computer model, select the properties we want to report on, and export them to the CSV that was specified in the $Results variable at the beginning.

Now you have a CSV with a list of all of the computers in your environment (that report to that particular WSUS server) and their IP address, make, and model.  Happy reporting!

2 comments:

  1. Is it possilble to get OS version in the same scope ?

    ReplyDelete
  2. use osdescription
    Select-Object fulldomainname,ipaddress,Osdescription,make,model

    ReplyDelete