How to Get Email Addresses for an AD Security Group with Powershell

Here's a script to pull the email addresses out of an AD Group and drop them into a file.  Probably doesn't come up too often, but it did today, so there:



foreach($user in get-adgroupmember MyADGroupName)
{
   $emails +=  (get-aduser $user.SamAccountName -property 'emailaddress').emailaddress +";"
}


$emails | out-file c:\temp\MyAdGroupEmails.txt 

Labels: