Someone recently asked about the best way to perform bulk GPO renames. Of course, there are probably many reasons why you would want to do this (e.g. moving to a standard naming convention, cleaning up mis-named GPOs, etc.) but for my money, there is one technology that makes this easy–PowerShell!
There are (at least) two ways to do this in PowerShell, depending upon which version of Windows you have. If you are in a Windows 7 or Server 2008-R2 world, then the Microsoft-supplied GroupPolicy module makes it easy.
Simply open PowerShell, type:
Import-Module GroupPolicyAnd then you can use the aptly named Rename-GPO cmdlet to get the job done, as so:
rename-gpo “My Security GPO” -TargetName “My Security GPO 2”Simple!
If you don’t have Win7 or Server 2008-R2, no problem. You can use our GPMC cmdlets, available at www.sdmsoftware.com/freeware, to solve it almost as easily! Specifically, the Get-SDMGPO cmdlet will let you get a reference to a GPO and from there, you can modify the DisplayName property on the GPO to change the GPO’s name, as follows:
(Get-SDMgpo “My Security GPO” -native).DisplayName = “My Security GPO2”So, this is a bit more complicated than Rename-GPO but not much–still a one-liner. It basically calls Get-SDMGPO to get a reference to the current GPO by name and uses the -native parameter so that the reference we get is a COM object. Once we do that, we can set the value of the DisplayName property to the new value and we’re done!
Now, since the title of this blog post includes the word “bulk” we should talk about how you can scale this up. There’s a couple of ways to do this across multiple GPOs at once. Probably the easiest is to create CSV file that includes the list of GPO names that you want to change and the new name for each, as such:
OldName,NewName Securitypolicy,Marketing Security Policy Desktop Lockdown,Marketing Desktop Lockdown IE Lockdown, Marketing IE Lockdown
Once you have that CSV file, you can use the Import-CSV cmdlet to bring those values into a variable in PowerShell and iterate through them to rename all GPOs. The following shows how to do this using our SDM GPMC cmdlets:
$rename = import-csv .gporename.csv foreach ($item in $rename){(Get-SDMgpo $item.OldName -native).DisplayName = $item.NewName}After importing the CSV list into a variable called $rename, we use the foreach cmdlet to iterate through each line of the CSV and pass that to our rename command that we used above, simply replacing old and new GPO names with the properties OldName and NewName from the CSV file. Easy!
Hope this helps with your bulk renaming operations. PowerShell makes it painless!
Darren