$_.altRecipient -ne $null NOT finding values

Welcome Forums General PowerShell Q&A $_.altRecipient -ne $null NOT finding values

Viewing 3 reply threads
  • Author
    Posts
    • #52633
      Participant
      Topics: 120
      Replies: 258
      Points: 229
      Rank: Participant

      I have this one liner:

      Get-ADUser -Filter * -Credential $creds | Where-Object {$_.altRecipient -ne $null}

      ...to find all users in our org that may have a value. It's not even returning my test User for which I did enter a DN value.

      What is my error?

      thanks

    • #52637
      Participant
      Topics: 0
      Replies: 61
      Points: 0
      Rank: Member

      Get-aduser returns a subset of ad properties, to get other properties that aren't in that default set you can specify them with the -properties parameter.

      Alternatively, it would also be more efficient to use the -filter parameter rather than where-object.

    • #52643
      Participant
      Topics: 0
      Replies: 61
      Points: 0
      Rank: Member
      Get-aduser -filter {altrecipient -like '*'}

      That should work, I think.

      • #52815
        Participant
        Topics: 120
        Replies: 258
        Points: 229
        Rank: Participant

        Thanks Craig, that indeed did work for me. Appreciate the reply, but the odd thing is, even though it found my test User object that has a value for altRecipient, the select operation doesn't show the value. How can I reveal the actual value as well as find the User object that contains it?

        Get-aduser -filter {altRecipient -like '*'} -Credential $creds | select altRecipient
        
        altRecipient
        ------------
                    
    • #52834
      Participant
      Topics: 18
      Replies: 573
      Points: 32
      Rank: Member

      The filter doesn't require the property however you must include it for it to display.

      Get-aduser -filter {altRecipient -like '*'} -Credential $creds -properties altrecipient

      • #52908
        Participant
        Topics: 120
        Replies: 258
        Points: 229
        Rank: Participant

        Thanks Dan -properties altrecipient solved it.

        Learning!

Viewing 3 reply threads
  • The topic ‘$_.altRecipient -ne $null NOT finding values’ is closed to new replies.