SideIndicator Omitted for Object-Compare -PassThru with Singular Result

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

This topic contains 6 replies, has 3 voices, and was last updated by

 
Participant
3 weeks, 2 days ago.

  • 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: 1085
    Points: 3,651
    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: 8
    Replies: 1213
    Points: 756
    Helping Hand
    Rank: Major Contributor

    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.

You must be logged in to reply to this topic.