SSR-IS
asked on
Bulk rename 450 AD Groups with Powershell
Hi,
normally I try to script for myself and see how far I get - and ask my questions when necessary. Right know I could need a little help from scratch ;-)
What I want to do:
I have a OU with nearly 1000 Groups and need to rename about 450 of them. The current naming is something like AAA-BBB-CC-XXXXX. The new groups should be named AAA-BBB_PC-XXXXX.
Is there a chance to to the renaming with powershell?
Regards
Steffen
normally I try to script for myself and see how far I get - and ask my questions when necessary. Right know I could need a little help from scratch ;-)
What I want to do:
I have a OU with nearly 1000 Groups and need to rename about 450 of them. The current naming is something like AAA-BBB-CC-XXXXX. The new groups should be named AAA-BBB_PC-XXXXX.
Is there a chance to to the renaming with powershell?
Regards
Steffen
Not sure what version of OS you are running. If have 2008R you could use the MS AD cmdlets if not you can use the quest cmdlets.
You could try something like this if the group names you specified are the same.
Test first in dev or seperate OU.
$groups = get-qadgroup -searchroot "OU=Groups,DC=Domain,DC=Lo cal" | Where {$_.name -match "AAA-BBB-CC"}
foreach ($group in $groups){
$name = $group.name -replace "-CC-", "_PC-"
rename-qadobject $group -NewName $name
}
You could try something like this if the group names you specified are the same.
Test first in dev or seperate OU.
$groups = get-qadgroup -searchroot "OU=Groups,DC=Domain,DC=Lo
foreach ($group in $groups){
$name = $group.name -replace "-CC-", "_PC-"
rename-qadobject $group -NewName $name
}
ASKER
Okay thanks - I´ll try this over the weekend!
ASKER
Hello KenMcF,
your script work absolutely perfect!
Theres one thing which should be done if possiible. The Pre-Windows2000 name is not changed with this scipt. I think it doesn´t really matter, but it would be better to do this even also.
Maybe you can extend your script, if you don´t mind?
Regards
Steffen
your script work absolutely perfect!
Theres one thing which should be done if possiible. The Pre-Windows2000 name is not changed with this scipt. I think it doesn´t really matter, but it would be better to do this even also.
Maybe you can extend your script, if you don´t mind?
Regards
Steffen
try this
$groups = get-qadgroup -searchroot "OU=Groups,DC=Domain,DC=Lo cal" | Where {$_.name -match "AAA-BBB-CC"}
foreach ($group in $groups){
$name = $group.name -replace "-CC-", "_PC-"
rename-qadobject $group -NewName $name | set-qadgroup -samaccountname $name
}
$groups = get-qadgroup -searchroot "OU=Groups,DC=Domain,DC=Lo
foreach ($group in $groups){
$name = $group.name -replace "-CC-", "_PC-"
rename-qadobject $group -NewName $name | set-qadgroup -samaccountname $name
}
ASKER
Thanks for you very quick reply.
There´s an error now, where Powershell states that the pipe element is not allowed to be empt.
There´s an error now, where Powershell states that the pipe element is not allowed to be empt.
Have all the groups been renamed already and just the samaccountname needs changed now?
ASKER
Oh, I set the naming back to the starting position - which means all groups have the naming AAA-BBB-CC-XXXXX again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don´t know why, maybe I had a typing error, I copied your script again and now it works.
Thanks a lot, espacially for support on sunday! 500 pts to you!
Steffen
Thanks a lot, espacially for support on sunday! 500 pts to you!
Steffen
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/1f55bf09-ad10-4d83-84c0-bf54e73bc023