Thursday, August 9, 2012

Powershell & Active Directory : “Find all users Email ID’s in Active Directory Using Powershell”.

Hi,

My todays task was to create a list of our all of our “Active Directory” users email Id’s. Normally you can do this easily using download your global address list of exchange server and export in to the file.

But remember Powershell is all about automation. Now imagine, your manager told you that every fortnightly he want’s a list of all users email id so that he can use it for sending some company wise “News”. I know you don’t want to so this manually after every 15 days. So why not to automate is and save some manual task, so that we can steal some time to spend on “Facebook”  ;o).

Okies, lets start , before running any cmdlets make sure you have RSAT tools installed.

The task is simple we can use Get-Aduser and and use –Filter * to find all users, and in –Properties choose Email Address to show and then pipe output to Select-Object cmdlet and choose to display Name and Email Address in the output.

Get-ADUser -Filter *  -Properties EmailAddress  | Select Name,EmailAddress 

Okies, we got what we want,,,,But wait,,, there are few users who don’t have any Email Address and i don’t want them in to my output file, let’s filter it more.


09-08-2012 19-30-52


I have added a one more cmdlet to the command , which is Where-Object , before Selecting the object we choose to show only those users whose Email Address files in not null.

Get-ADUser -Filter *  -Properties EmailAddress  | where { $_.EmailAddress -ne  $null }  | sort  | Select Name,EmailAddress

Now we can add Export-CSV cmdlet in to the End so that we have a output stored in to a .CSV file.

Get-ADUser -Filter *  -Properties EmailAddress  | where { $_.EmailAddress -ne  $null }  | sort  | Select Name,EmailAddress | Export-Csv D:\email_ID.txt

and the output file should be look perfect like this.


09-08-2012 19-38-59


Task finished….


and have a nice day and


Happy Janmashtami Everyone :o)


krishna_animated


Thanks


Aman Dhally


join aman on facebook Join aman on Linkedin follow aman on Twitter

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.