Rename Active Directory Groups with Powershell

Renaming Active Directory groups turned out to be easier than I though. There are two core commands needed, rename-adobject and set-adgroup. Here’s a simple example:

get-adgroup -identity “LongGroupName” | %{set-adgroup -samaccountname “ShortName”; $_ | rename-adobject -newname “ShortName”}

To rename all of the groups in an OU based on some pattern, you could try this:

get-adgroup -filter * -searchbase ‘OU=Groups,DC=fabrikam,DC=com’ | %{$newname = “Groups -” + $“-“,4)[3]; $_ | set-adgroup -samaccountname $newname; $_ | rename-adobject -newname $newname}

Key points on this example:

  • searchbase is used to return all groups in an OU
  • I used the split method to strip out preceding sections of the original group name, seperated by -. This would be changed to suite your environment
  • Pass it all down the pipeline and execution is pretty fast.



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