0

I'm trying in powershell to output all AD users from a certain group with no data in the email address field.

I have the following command:

get-aduser -filter * -properties * | where {!$_.emailaddress} | select-object samaccountname | export-csv c:\email\noemailusers.csv

But I'm trying to narrow down the results to only users who are member of a certain group.

Any help is much appreciated!

1 Answers1

3

Start from the group and get a members list; get the AD user object for each group member; check whether the user has an email address.

Get-ADGroupMember $yourgroup | Get-ADUser -Properties mail | where { $_.mail -eq $null }
Massimo
  • 70,200
  • 57
  • 200
  • 323
  • Thank you so much! If I have multiple groups that are similar, is it possible to grab all of the users from all of them with some sort of wildcard operator, or should I run a separate command for each group? Thanks again! – user970505 Jun 16 '22 at 17:31
  • You can run Get-ADGroup with an appropriate filter and then pipe its output into Get-ADGroupMember. – Massimo Jun 16 '22 at 20:40
  • You can also accept an answer if it solves your problem ;) – Massimo Jun 16 '22 at 20:41
  • 1
    Thanks again for all your help! – user970505 Jun 16 '22 at 21:15