Hello Everyone,
I’m new PS and have really been enjoying it so far. I’ve been coming here in search of answers and appreciate the communities input.
I have been asked to rename some security groups in AD and have run into some issues.
(I running ps v5 and using the “rename-adobject” command)
Rename-ADObject [-Identity] ADObject [-NewName] string
The below script is really to test/debug/practice, before gathering all the security groups, objects, filters, etc.
For now I’m trying to rename two accounts in a csv file. The script seems to work with -whatif (output below), but as soon as I removed it. I receive the following error:
With -Whatif: = no errors
$dn | ForEach-Object {Rename-ADObject $_.distinguishedname -NewName $NewName -WhatIf}
What if: Performing the operation “Rename” on target “CN=#US.SDTest-RW,OU=SharedDrive Groups,OU=Corporate,OU=Do
main-Groups,DC=Domain,DC=com”.
What if: Performing the operation “Rename” on target “CN=#US.SDTestv2-RO,OU=SharedDrive Groups,OU=Corporate,OU=
Domain-Groups,DC=Domain,DC=com”.
Removing -whatif: = Error
Rename-ADObject : The parameter is incorrect
At line:1 char:23
- … rEach-Object {Rename-ADObject $_.distinguishedname -NewName $NewName}
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sample Script:
$renameSG = Import-Csv D:\scripts\testSD.csv
#works up to here - import Security Group Names
$Oldname = $renameSG.oldname
#works up to here - Add Oldname strings into Var
$dn = foreach($group in $Oldname){Get-ADGroup -Identity $group}
#works up to here - create new var with SG names
$NewName = $renameSG.newname | out-string
#works up to here
#Testing >> $dn | ForEach-Object {echo $_.distinguishedname}
$dn | ForEach-Object {Rename-ADObject $_.distinguishedname -NewName $NewName}
Any help would be greatly appreciated. Best of all, I’d like to learn why this is not working. I thought using out-string cmdlet for $NewName would convert output to strings which then can be used for the -NewName parameter.
Thanks in advance.