Change 'header'

This topic contains 6 replies, has 3 voices, and was last updated by  Tony Wainwright 3 years, 7 months ago.

  • Author
    Posts
  • #15208

    Tony Wainwright
    Participant

    Hi

    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:
    # http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/17/use-powershell-to-perform-basic-administrative-tasks-on-wsus.aspx

    #Connect to WSUS Server named wsus
    [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
    $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')?

    Thanks
    Tony

  • #15209

    Dave Wyatt
    Moderator

    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
    
  • #15211

    Tony Wainwright
    Participant

    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?

  • #15213

    Tony Wainwright
    Participant

    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.

    Cheers

  • #15214

    Richard Siddaway
    Moderator

    Tony

    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)

  • #15228

    Tony Wainwright
    Participant

    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.

  • #15212

    Dave Wyatt
    Moderator

    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.

You must be logged in to reply to this topic.