A request came down from the suits asking if we could export the first and last names, titles, and email addresses of our organization for an outside agency. This agency would like to add each all of our employees as contacts on their mail server.
Seeing as how we ask for .csv files when requesting information from other agencies, we decided to reciprocate the favor and provide a .csv file to this agency. Comma Separated Value files make it easier to run scripts against and facilitate automation.
Here's the script that we came up with in order to get the information requested.
Get-User | Where-Object {$_.RecipientTypeDetails -eq "UserMailbox" -and $_.title -ne "intern" -and $_.WindowsEmailAddress -like "*@organization.org"} | select LastName, FirstName, Title, WindowsEmailAddress |Export-Csv "c:\emailAddressList.csv"
Here's what it does:
It gets all users that have a mailbox and do not belong to interns. It verifies that the email address is one from our organization and not a mail enabled contact. It then collects the information that was requested, i.e. name, title, and email address, and exports those items to a .csv file.
Thanks to Powershell, this operation didn't take long to complete and we were thanked for the quick turn around. We were a bit disappointed that the script was completed so quickly that we had to work on other boring and not-so-fun tasks.
I hope you learned something. This could have been accomplished many ways, but we found this to be simple, yet effective.