Powershell is greatness…

Most of the mailbox migrations went really well, and I only had about 100 mailboxes fail to move. Not bad when I was moving >1000, (granted, a 10% failure rate isn’t really GOOD, either). I got them rescheduled to run tonight, so hopefully it will go smoothly.

In the midst of all the moves, we decided to create another SG for a department who has quite a bit of email traffic. Other than actually talking to the managers of the teams that make up that group and writing down the names, the only way to get a list of the users in those groups was to look at a couple AD groups. Since my mailbox migration script uses the mailbox alias, (which is usually the user name from AD), if I had created my new input file using the GUI, that would mean opening the group in ADUC, going to the Members tab, double-clicking each user, and then going to the Account tab on the user properties dialog. Way too much work!

Here’s all it takes in Powershell:

Get-ADGroupMember "AD_Group_Name" | ft SamAccountName -HideTableHeaders >> c:\temp\ad.txt

Granted, this assumes you run the “Active Directory Module for Windows Powershell.” Setup instructions here, and reference here.

Run that little command for each of the groups I need to pull names for, clean up a little whitespace in C:\temp\ad.txt, and set up the scheduled task!

Oh! And I couldn’t figure out exactly what the name of one of those groups was, but I knew it contained the word “central”. So I used a little of the Powershell Expression Language to search for it:

Get-ADGroup -filter {name -like "*central*"}
Posted in Powershell

Leave a comment