HOWTO : Bulk group name change in the Active Directory by adding a prefix using powershell

0 Flares 0 Flares ×

During my work I faced many scripting challenges, the one I describe now is very simple and this post will be really short, but dear Reader it can help you to solve some similar cases. So in my case issue was  to change all Active Directory group names in one organizational unit by adding the prefix. For example, there a domain “TDA.internal” containing OU=HR and OU=Groups below in HR, the case is to add to all groups in the organizational unit,  “HR_” prefix.
It will be one-liner – I really love them.
I’m working on Windows Server 2012 R2 with Active Directory domain and forest functional levels : Windows Server 2012 R2 So let’s start Powershell or Powershell ISE, up to you, import Active Directory module using command
Import-module ActiveDirectory #to be able to use Powershell AD commands
If the command does not work, you need to add proper feature on Windows Server or install RSAT, but it’s not the purpose of this post and define some variables

Ok, the variables are defined, of course I could put them directly into powershell to have it “real” one-liner, but like this it’s more “professional”. Now comes the command, the “%” character in the command means “foreach-object”.

And it’s done. Pretty simple right.
Last part is, how to change it back. In our case the prefix was a string with length – 3 characters and it will be removed using “Substring” function, so let’s move it back to the previous name.

And it’s done.
Thanks for reading and please do not click “Like” or “Tweet”, I’m not using facebook or tweeter, but if you have any questions don’t hesitate to contact me by form below.

0 Flares LinkedIn 0 Google+ 0 Facebook 0 Twitter 0 0 Flares ×

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.