Replace prefix for all group names in a certain OU

I am trying to take all groups that belong to a specific OU, and then for each of them, rename their "Groupname", "SAMAccountName", and "NTAccountName" accordingly.

So of these 3 values, the groups name would be like:
"OLD_Group1".
"OLD_Group2"
"OLD_GroupAbCdE"

Not the actual object name in AD but the properties mentioned above.

Essentially of all these groups in their specific OU, I'd be replacing "OLD_" with "NEW_" in the strings to rename them accordingly.

What I've got so far is:

$testgroup = Get-QADGroup -SearchRoot 'OU=TESTING,OU=Services,DC=cafenet,DC=com'
foreach ($group in $testgroup) {Set-QADGroup -GroupName -replace "OLD_","NEW_"; Set-QADGroup -SAMAccountName -replace "OLD_","NEW_"; Set_QADGroup -NTAccountName -replace "OLD_","NEW_";

Open in new window



Will this not work?
garryshapeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
Not sure why you want to change the NTAccountName (SID)?

Try the following...
You need to construct your CSV like below...
GroupSAM NewName NewSAM
Group1       Group21   Group21
Group2       Group31   Group31
etc...

Import-module activedirectory
$Groups = import-csv "c:\filename.csv"
ForEach ($Group in $Groups) {
$Group.GroupSAM
$Group.NewName
$Group.NewSAM
Set-ADGroup -Identity $Group.GroupSAM -DisplayName $Group.NewName -SamAccountName $Group.NewSAM
}

Open in new window


Will.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garryshapeAuthor Commented:
This looks pretty cool but is there a way to pipe it instead of importing from csv? The CSV legwork may be too much as there would be an ongoing need to do this I think
0
Justin YeungSenior Systems EngineerCommented:
I am not sure about Quest AD command but this doesn't look right on.

$testgroup = Get-QADGroup -SearchRoot 'OU=TESTING,OU=Services,DC=cafenet,DC=com'
foreach ($group in $testgroup)
{
Set-QADGroup -identity $group.identity -DisplayName $($group.displayname -replace "OLD_","NEW_") -SamAccountName $($group.SamAccountname -replace "OLD_","NEW_")  
}

Open in new window


I don't see NTAccountName and GroupName as a valid parameter in Set-QADgroup

Set-QADGroup [-Identity] <IdentityParameter> [-Connection <ArsConnection>] [-ConnectionAccount <string>] [-ConnectionPassword <SecureString>] [-Control <hashtable>] [-Credential <PSCredential>] [-Description <string>] [-DeserializeValues] [-DisplayName <string>] [-Email <string>] [-ExcludedProperties <string[]>] [-GroupScope <GroupScope>] [-GroupType <GroupType>] [-IncludedProperties <string[]>] [-Keywords <UpdateStringParameter[]>] [-ManagedBy <IdentityParameter>] [-ManagerCanUpdateMembershipList <Boolean>] [-Member <UpdateIdentityParameter[]>] [-Notes <string>] [-ObjectAttributes <ObjectAttributesParameter>] [-Proxy] [-Published <Boolean>] [-RequireManagerApproval <Boolean>] [-RequireSecondaryOwnerApproval <Boolean>] [-SamAccountName <string>] [-SecondaryOwner <UpdateIdentityParameter[]>] [-SecondaryOwnersCanUpdateMembershipList <Boolean>] [-Service <string>] [-UseDefaultExcludedProperties <Boolean>] [-UseGlobalCatalog] [-Confirm] [-WhatIf] [<CommonParameters>]
0
garryshapeAuthor Commented:
Ok yeah I will try it. It actually doesn't show up as a parameter but it does auto tab completion if I type "-Grou" for example then hit tab, it will complete as "-GroupName" interestingly.
0
Justin YeungSenior Systems EngineerCommented:
well as I mentioned I haven't used Quest AD tool.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.