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.
Something like this:'
Get-ADGroup -filter {name -like 'VIPEmail'} |
Get-ADGroupMember -Recursive |
Get-ADUser -Properties Mail |
select -ExpandProperty Mail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With