≡ Menu

Find list of computers(targets) in a WSUS group using PowerShell

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.

{ 12 comments… add one }
  • Raj October 22, 2014, 7:06 pm

    This was very helpful article does the trick.

  • Andrew Thomas October 12, 2015, 7:29 am

    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)

    • TechiBee October 12, 2015, 8:53 pm

      Thanks for sharing it.

    • Skylab May 23, 2017, 12:10 pm

      This worked fine for me.

  • Ram March 5, 2016, 9:54 pm

    Can we get the list of kb article available in the WSUS for update and superceded article of each KB?

    • Wintel Rocks March 23, 2016, 11:02 pm

      Haven’t tried it before. Will let you know if I come across any

  • Ram March 5, 2016, 9:56 pm

    I need superseded kb article information please mail me on Bhawanraj@gmail.com

  • Thiru March 16, 2016, 11:38 am

    You can also try
    $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer()

    This works when you’re running the script/command in the server itself.

  • Joe June 5, 2017, 4:09 am

    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 ?

  • Joe June 5, 2017, 4:15 am

    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

Leave a Comment