SideIndicator Omitted for Object-Compare -PassThru with Singular Result

Welcome Forums General PowerShell Q&A SideIndicator Omitted for Object-Compare -PassThru with Singular Result

Viewing 4 reply threads
  • Author
    Posts
    • #179694
      Participant
      Topics: 1
      Replies: 4
      Points: 7
      Rank: Member

      I'm comparing 2 Get-ADGroupmember arrays:
      $DiffMems = (Compare-Object $users1 $users2 -PassThru)
      OR
      [array]$DiffMems = (Compare-Object $users1 $users2 -PassThru)
      If the results contain more than one user I get a SideIndicator of => or <=. 2 results
      If the results contain only a single user I get no side indicator the field drops to the bottom of the list and I have a WriteErrorStream field with no value.
      single result
      Unfortunately I need to use the side indicator to tailor an email with the results of the group comparison.

      What am I missing?

    • #179811
      Senior Moderator
      Topics: 8
      Replies: 1152
      Points: 4,000
      Helping Hand
      Rank: Community Hero

      Try not using -PassThru

      • #179967
        Participant
        Topics: 1
        Replies: 4
        Points: 7
        Rank: Member

        I need to use the passthru because I use the output to pull a Get-ADPrincipalGroupMembership.
        I haven't had much luck doing that with the default output.

        Thanks for the suggestion though.

    • #179865
      Participant
      Topics: 10
      Replies: 1375
      Points: 1,481
      Helping Hand
      Rank: Community Hero

      There are times where a single object is converted to a scalar value, so it could be comparing an array to a single item. You might try just wrapping the variables in @() to ensure they are arrays, even with a single item.

      $DiffMems = (Compare-Object @($users1) @($users2) -PassThru)
      
      • #179970
        Participant
        Topics: 1
        Replies: 4
        Points: 7
        Rank: Member

        I tried surrounding with the @() but it doesn't seems to have an effect. Tried it with and without the [array] on the variable assignment. It makes no difference.
        [array]$DiffMems = (Compare-Object @($users1) @($users2) -PassThru)

        It is interesting that this issue only comes up when using the -PassThru option. If it's left off it gives the correct result with a SideIndicator but then my subsequent Get-ADPrincipalGroupMembership fails with the error:
        Cannot convert the "@{InputObject=CN=Mike; SideIndicator=<=}" value of type "System.Management.Automation.PSCus tomObject" to type "Microsoft.ActiveDirectory.Management.ADPrincipal".

        There doesn't seem to be a property I can pass to the Get-ADPrincipalGroupMembership  using the default output.

        Thanks for the suggestion.

         

    • #179997
      Participant
      Topics: 1
      Replies: 4
      Points: 7
      Rank: Member

      I've also attempted to encapsulate the failing compare into a trace-command and it does identify a problem for each compare:
      DEBUG: ETS Information: 0 : Exception System.Management.Automation.PSArgumentException: Cannot compare "CN=Tessa" because it is not IComparable.

      I thought that might have been it so I tried comparing on just one property samaccountname and it no longer throws the error but I still get no value for SideIndicator and the writeerrorstream with no value. The trace just shows all the samaccountnames with no errors:
      DEBUG: ETS Information: 0 : WriteLine A0024
      (where A0024 is the samaccountname)

    • #180219
      Participant
      Topics: 1
      Replies: 4
      Points: 7
      Rank: Member

      I'm thinking it has to do with something similar to the issue described here:
      https://github.com/PowerShell/PowerShell/issues/6512
      But that doesn't tell me how to resolve or workaround the issue.

      I'm going to rewrite the whole thing in c# unless someone has an idea.

Viewing 4 reply threads
  • The topic ‘SideIndicator Omitted for Object-Compare -PassThru with Singular Result’ is closed to new replies.