Compare-Object issue

Welcome Forums General PowerShell Q&A Compare-Object issue

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
1 year, 6 months ago.

  • Author
    Posts
  • #69280

    Participant
    Points: 0
    Rank: Member

    The other day I stumbled over the fact that Compare-Object doesn't handle a Null object very well. This does of course make some sense but, in my case I had to come up with a workaround since the objects being passe to the Compare-Object might very well most of the time be Null objects. I'm comparing AD Group members.. and Compare-Objects side indicator makes this really easy.

    So this is my question, is the solution I'll outline below the "correct" way of solving this issue, or is there a better practice?

    What I did – was I created my own Compare-ObjectADGroupMember function which takes the same two parameters as Compare-Object ReferenceObject and DifferenceObject. I then measure if either of these are Null and if so I assign them a dummy value. At this point neither objects contains a Null vall and I run the regular Compare-Object command. In the end I remove any dummy values from the output of Compare-Object and return that.

    Is this a healthy approach or could it be improved? My function is very ADObject specific

  • #69364

    Keymaster
    Points: 1,625
    Helping HandTeam Member
    Rank: Community Hero

    Have you looked at Compare-Object2 in https://github.com/alx9r/ToolFoundations?

The topic ‘Compare-Object issue’ is closed to new replies.