Author Posts

May 12, 2014 at 6:18 am


I am looking to compare a list of computers on my wsus server with a list of computers in AD, using the following code:

# Source:

#Connect to WSUS Server named wsus
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer("wsus”,$False)

# Get list of computers
$a = $wsus.GetComputerTargets() | Select FullDomainName | Sort FullDomainName
$b = Get-ADComputer -Filter * | Select DNSHostName | Sort DNSHostName
Compare-Object $a $b

I know this doesn't work and I know why – the field names are different (FullDomainName and DNSHostName). Is there a way I can 'alias' DNSHostName to FullDomainName (similar to the SQL keyword 'AS')?


May 12, 2014 at 6:27 am

Yep, you can use constructed properties in one or both of your calls to Select-Object:

$a = $wsus.GetComputerTargets() | Select FullDomainName | Sort FullDomainName
$b = Get-ADComputer -Filter * | Select @{ Name = 'FullDomainname'; Expression = { $_.DNSHostName } } | Sort FullDomainName

May 12, 2014 at 7:09 am

Thanks Dave. This is working better but has thrown up a different problem. It's now showing a number of computers that are in both variables (the obvious difference is in the capitalisation). I've tried using the CaseSensitive switch to no avail. Is there a way to make the contents of both objects lowercase?

May 12, 2014 at 7:46 am

What parameters are you passing to Compare-Object? Here's what worked for me, in a quick test (but I'm not actually getting any data from WSUS for this, just AD):

Compare-Object $a $b -Property FullDomainName

Edit: This test was done with the same data, but different case. Unless I added the -CaseSensitive switch, PowerShell treated the two collections as identical.

May 12, 2014 at 7:53 am

Thanks Dave, that worked a treat. I'm just getting started with powershell – know what I want to do and a rough idea how it'll work, but just need to get to grips with some of the finer details.


May 12, 2014 at 8:21 am


If you're just starting you may want to read Learn PowerShell in a Month of Lunches by Don Jones and if you're doing a lot with AD you should read Learn AD Management in a Month of Lunches by me (it covers a lot on using PowerShell with AD)

May 13, 2014 at 2:30 am

Thanks for all your help Richard, I've just ordered both books from Amazon and am looking forward to getting started. I now seem to remember PowerShell in a Month of Lunches being mentioned in the PowerShell VA Jumpstart with Jason Helmick and Jeffrey Snover.