In this post, I will demonstrate how to query the list of computers in a WSUS group using PowerShell.
Introduction
We all know that WSUS is a patching tool and we can create custom groups inside it to manage the approvals and to do better organization. When you have a various groups in WSUS console, how do you know the list of computers currently members of a given WSUS group. The PowerShell script described in this article will help you in querying this information.
Connect to WSUS server
First of all, we need to connect to the WSUS server from which you want to query the group information. The below code will help you to connect to a WSUS server and $wsus stores the reference information of that.
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer("SRVWSUS1",$False)
List all WSUS groups
Once connected to the server, we need to find out what all groups available in that particular WSUS server. This can be done by calling GetComputerTargetGroups() method.
$wsus.GetComputerTargetGroups()
Get the WSUS group you want
After you decide on the group that you want to query, just filter the output of the above command. For example, if the group that I am interested in is “America Computers”, then I can use something like to get the group I need.
$mygroup = $wsus.GetComputerTargetGroups() | ? {$_.Name -eq "America Computers"}
List members of WSUS group
Once the group reference object is available, its matter of calling querying the member names (aka targets) of this group by invoking the method GetComputerTargets(). The output will contain list of computer objects along with other properties like last sync time, last reported time, etc. The below command will return all target computers FQDNs.
$mygroup.GetComputerTargets() | select FullDomainName
Hope this helps and happy learning.
Comments on this entry are closed.
This was very helpful article does the trick.
Glad to know that it helped.
Great article
If you get the following error when trying to connect to the WSUS server:
Exception calling “GetUpdateServer” with “2” argument(s): “The request failed with HTTP status 404: Not Found.”
You may need to specify the port that WSUS is using. To do this, use the third parameter in the connection string such as:
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(‘WSUS-Server’,$False,8530)
Thanks for sharing it.
This worked fine for me.
Can we get the list of kb article available in the WSUS for update and superceded article of each KB?
Haven’t tried it before. Will let you know if I come across any
I need superseded kb article information please mail me on Bhawanraj@gmail.com
You can also try
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer()
This works when you’re running the script/command in the server itself.
Everything works fine as far as listing all of the groups in WSUS. But when I add the last lines to list the members of the selected group, I don’t get anything returned. Just blank lines. Any idea what I am doing wrong ?
I modified the script to dump all of the computers from every group in WSUS
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(“drfvjmscwsusp01”,$False)
$wsus.GetComputerTargets() | select FullDomainName
Great!!
Well, It turns out that I really do need to export the computers by group… so I run this code and it gives me the entire list of servers – not just the ones in the specified group…. any idea where I’m going wrong?
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(“drfvjmscwsusp01”,$False)
$wsus.GetComputerTargets() | select FullDomainName
$mygroup = $wsus.GetComputerTargetGroups() | ? {$_.Name -eq “Prod DMZ Servers”}
$mygroup.GetComputerTargets() | select FullDomainName
OK, I got it working. Same code, except I think the name is case sensitive.
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(“drfvjmscwsusp01”,$False)
$mygroup = $wsus.GetComputerTargetGroups() | ? {$_.Name -eq “PROD DMZ Servers”}
$mygroup.GetComputerTargets() | select FullDomainName
My bad – I believe I had an extra line of code.
($wsus.GetComputerTargetGroups() | where {$_.Name -eq “All Computers”}).getcomputertargets()
returns values of only one of the Sub-Child Groups. Inshort this does not seem to show all computers.
Neither does $wsus.getcomputertargets()
Both these results are same, but does not show all the client computers that i see in the WSUS MMC.
Any ideas?
I remember this is something to do with querying downstream WSUS servers vs root WSUS servers.
Hi !
I work for my company to remove with a powershell script only one PC with his name from wsus server. But, I have searched since 8:00 pm but I did not found any solution
Can you help me ?
I believe this is what everyone was looking for. This scripts list all the groups, counts the members and lists the members.
[reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer()
foreach( $group in $wsus.GetComputerTargetGroups() )
{
Write-Host “Group: ” $group.Name ” – ” $group.GetComputerTargets().Count ” member(s)”
$group.GetComputerTargets()|select FullDomainName
}
Please let me know if this works for you. I’m not an expert at powershell but I needed this functionality so I spent 10 mins figuring it out.
All of this helped me. I am contributing what I did for my specific need. I wanted to see all of the servers by group in table format, also outputted to a file named for the group.
=========
[reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer()
foreach( $group in $wsus.GetComputerTargetGroups() )
{
# Write-Host “Group: ” $group.Name ” – ” $group.GetComputerTargets().Count ” member(s)”
$group.GetComputerTargets() | select RequestedTargetGroupName, FullDomainName | Sort-Object RequestedTargetGroupName | Format-Table -GroupBy RequestedTargetGroupName
}
Thank you Robinson for sharing.