Getting AD Contact with no Target Address

This topic contains 2 replies, has 2 voices, and was last updated by  Jack Harrison 1 year, 10 months ago.

  • Author
  • #50743

    Jack Harrison


    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

    Edmond Yee

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

  • #50794

    Jack Harrison

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

You must be logged in to reply to this topic.