Renaming Active Directory Groups in Bulk with Powershell and ActiveRoles Server

I said I was going to be blogging Powershell stuff and this is the first post.  The most important thing for me to point out is that I am a complete Powershell and scripting newbie, so when I get the basic things done that save me a load of time it really makes my day.  Today was one of those days where through a little research I managed to get 80 groups renamed in 3 separate environments with just a single line of code.  My environment has an ActiveRoles Server installation  (v6.5) so I was using the ActiveRoles Management Shell for Active Directory ( which is a set of Powershell cmdlets.  Here’s how I did it:

First, I created a CSV file with just two columns.  The first column had a header of ‘oldname’ and the second had a column header of ‘newname’  Can you see where this is going?

I populated the columns with the existing group names in ‘oldname’ and the target name in ‘newname’ and saved it as c:\grouprenames.csv

I then launched the ActiveRoles Management Shell and run the command:

connect-qadservice –proxy

This connected me to the ActiveRoles service rather than running through the native Active Directory provider.

Now, it’s as simple as running the following code:

import-csv ‘c:\grouprenames.csv’ | ForEach-Object {Get-QADGroup –Name $_.’OldName’ | Rename-QADObject –NewName $_.’NewName’ | Set-QADGroup –SAMAccountname $_.’NewName’ –Displayname $_.’NewName’ | Format-List Name,sAMAccountname,DN}

The above command will do the following for each line in the CSV:

  1. Retrieve the Group specified in the OldName column
  2. Rename it to the name specified in the NewName column
  3. Set the SAMAccountName and Display Name values to the New Name
  4. Show on the screen the new values it has set for confirmation

Through this single command I now have something I can use every time I need to rename groups by just amending the CSV content and since I used the ActiveRoles service to make the change, all changes were subject to any Policies and Restrictions I had set though the ActiveRoles configuration.


Categories: Active Directory, ActiveRoles, Powershell

5 replies

  1. This worked perfectly, although I also wanted to change the Alias for my distribution lists. Any idea on how I can accomplish that? Thank you.

  2. Thanks for this Matt. It’s just what I need. I’m a powershell newbie and so far borrowing scripts and adapting them is the depth of my experience.

    I have to remove spaces from group aliases and found this code. It might help with Masana’s question.

    $DistributionGroups = Get-DistributionGroup | Where {$_.Alias -like “* *”}
    ForEach($DistributionGroup in $DistributionGroups) {Set-DistributionGroup $DistributionGroup.Name -Alias:($DistributionGroup.Alias -Replace ” “,””) -confirm:$false}

  3. Thanks Gary, that code is adaptable for what Masana needs. I am in the process of moving and dont have my lab up but as soon as I do I will test the code needed and post it.

    Thanks for the comment

  4. This is great. Thanks for posting!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: