Getting AD Contact with no Target Address

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Jack Harrison Jack Harrison 3 months, 3 weeks ago.

  • Author
    Posts
  • #50743
    Profile photo of Jack Harrison
    Jack Harrison
    Participant

    Hello

    I am trying to get a list of AD Contacts that are in a distribution group that do not have a Target Address set.

    I am able to get a list of all of the contacts in the group and to bring back the data I want by running the below

    $memberof=get-adgroup MyGroup | select -expandproperty distinguishedname
    Get-ADObject -Filter 'memberof -eq $memberof -and (ObjectClass -eq "contact")' -properties * |select name,mail,targetaddress
    

    I am then trying to amend this, so it will only bring back results where there is no target address, yet no matter what I do, I get errors in the code.

    The idea is then to mail enable the contact where the target address is blank with the value in the mail field (I already have the powershell for this)

    Thank you

  • #50789
    Profile photo of Edmond Yee
    Edmond Yee
    Participant

    It sounds like you need to pipe your statement to Where {$_.targetaddress -eq $null} before your select statement

  • #50794
    Profile photo of Jack Harrison
    Jack Harrison
    Participant

    Yes, this has brought the data back I need
    Thank you Edmond.

You must be logged in to reply to this topic.