MMbill
MMbill

Reputation: 67

Rename group in column A to group in column B

I am trying to get a script together to rename about 40 security groups. I have imported them all into a csv in column A and put the name I need them changed to in column B. here is what I have so far.

Import-Csv C:\test.csv | ForEach-Object{
    $item = $_;
    Get-ADGroup -LDAPFilter "(&(sAMAccountName=$($_.OriginalName)))" | Set-ADGroup -OriginalName $item.Renameto
}

Thank you very much for all your help!

Upvotes: 0

Views: 2057

Answers (1)

Jessie
Jessie

Reputation: 416

Import-Csv C:\test.csv | ForEach-Object{Rename-ADObject -Identity $_.ColumnAHeader -NewName $_.ColumnBHeader}

If possible, use the DistinguishedName in Column A. Otherwise you may have to use the partition parameter to specify the groups location.

You may have to remove Protect Object from accidental deletion. If so, try this:

Import-Csv C:\test.csv | ForEach-Object{
Set-ADObject -Identity $_.ColumnAHeader -ProtectedFromAccidentalDeletion:$false
Rename-ADObject -Identity $_.ColumnAHeader -NewName $_.ColumnBHeader -PassThru | Set-ADObject -ProtectedFromAccidentalDeletion:$true
}

Upvotes: 2

Related Questions