Change 'header'


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’)?


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

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?

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.

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.



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)

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.