Getting AD Contact with no Target Address

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

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

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