Compare-Object issue

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 4 weeks, 1 day ago.

  • Author
    Posts
  • #69280
    Profile photo of Anders Jarl Dalholm
    Anders Jarl Dalholm
    Participant

    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

You must be logged in to reply to this topic.