Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting email address of all users in Security Group

I'm trying to script something where I can get the email address of all users in an active directory security group.

What I have so far:

$Groups = Get-ADGroup -filter {Name -like "VIPEmail" } | Select-Object Name
ForEach ($Group in $Groups) {
  Get-ADGroupMember -identity $($group.name) -recursive | Select-Object samaccountname
}

Obviously this will only return the samaccountname, which it does. I replace samaccountname with EmailAddress, and it does nothing.

like image 819
DobotJr Avatar asked Sep 06 '25 03:09

DobotJr


1 Answers

Something like this:'

Get-ADGroup -filter {name -like 'VIPEmail'} | 
Get-ADGroupMember -Recursive |
Get-ADUser -Properties Mail |
select -ExpandProperty Mail
like image 153
mjolinor Avatar answered Sep 08 '25 07:09

mjolinor