Friday, 12 May 2023

How to rename Group name using PowerShell

 How to rename Group name using PowerShell


Csv File Format 




$Groups = Import-Csv c:\temp\"RenameGroups.csv"


foreach ($Group in $Groups)

{

    $TempOldName = $Group.OldName

$TempNewName = $Group.NewName

$TempGroup = Get-ADGroup $Group.OldName

    try

   {

    "In try: working on $TempOldName"

        Set-ADGroup -Identity $TempGroup -SamAccountName $TempNewName

        Rename-ADObject -Identity $TempGroup -NewName $TempNewName

        Write-Output ($TempOldName + " has been renamed to " + $TempNewName)

    }


    catch

    {

"in Catch for $TempOldName"

        Write-Output "Error: $_"

    }

}




No comments:

Post a Comment