/* ]]> */
Jul 012011
 

Here’s a sample script that demonstrates how to use the WSUS 3.0 API to  (1) list all defined computer Target Groups and (2) list of all computers subscribed to a group.

Note: This script is written to utilize the default (local) WSUS server. If you wish to run it against a remote server, find the appropriate “GetUpdateServer” call, un-comment it and specify your hostname and SSL option ($true or $false).

BONUS: I’ve always thought it would be useful to have a “Line Number” feature for lists produced via the Format-Table cmdlet. I have included here a very simple function called “GetLN” that achieves this using a $script: variable which is used as a counter. Use of this function requires that you first initialize to a value of -1 and then access via an “expression” from within the format-table call.

Sample Output:

Finally, here’s the code. Just download and run on your WSUS server.

 Posted by at 10:40 am

  2 Responses to “List WSUS Target Group Members with PowerShell”

  1. Hello , How can we modify this to script get the computers list from unassigned group and send it via email?

  2. Hey Nishanth,

    There may be a better way to do this, but off the top of my head….

    Assuming the “Unassigned Computers” group is always at index zero (I think it is), once could do something like:

    remove lines 54 thru 65 from the script

    append the following:

    $comp = $grp[0].getcomputertargets()
    $comp | select FullDomainName | out-file unassignedHosts.txt

    You can choose any level of detail from the $comp object, but I’ve just selected FullDomainName here.

    That gets you part way there.

    Next you just need to do the email part. See powershell help for the Send-Email cmdlet OR see my article ( http://poshtips.com/2009/11/09/sending-email-from-a-powershell-script/ ) if you want to send email directly via Dot Net.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Page optimized by WP Minify WordPress Plugin