Modify AD groups in bulk using PowerShell script

irfan Sayed 1 Reputation point
2021-05-04T05:20:25.887+00:00

$Groups = Import-CSV -path "C:\users\Name$\Temp\Grouptest.csv"
ForEach ($Object in $Groups)
{
$OldName = $Object.OldName
$NewName = $Object.NewName
Get-ADGroup $OldName | Rename-ADObject -NewName $NewName

}

Using above command I can can change group name, but not getting clue to change other attributes like SamaccontName, Proxyaddress, Emailaddress

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Anonymous
    2021-05-04T07:01:55.817+00:00

    Hi,

    You can set the properties using the Set-ADGroup cmdlet.

    Get-ADGroup $OldName | Set-ADGroup -Replace @{SamAccountName=$newAccountName; proxyAddresses=$newProxyAddresses; mail=$newmail }  
    

    https://learn.microsoft.com/en-us/powershell/module/activedirectory/set-adgroup

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. irfan Sayed 1 Reputation point
    2021-05-04T07:31:28.49+00:00

    Thx, since i ave to do for bulk of groups so the csv file i ave to create in te form of oldname, NewSamAccountName, Newproxyaddresses? Or sometingelse

    0 comments No comments

  3. irfan Sayed 1 Reputation point
    2021-05-04T07:52:52.223+00:00

    Let me know if the below scrip will help

    $Groups = Import-CSV -path "C:\users\Name$\Temp\Grouptest.csv"
    ForEach ($Object in $Groups)

    $OldName = $Object.OldName
    $SamAccountName = $Object.SamAccountName
    $ProxyAddresses = $Object.ProxyAddresses
    Get-ADGroup $OldName $SamAccountName $ProxyAddresses | Set-ADGroup -Replace @{SamAccountName=$newAccountName; proxyAddresses=$newProxyAddresses; mail=$newmail }

    0 comments No comments

  4. Anonymous
    2021-05-04T08:33:42.983+00:00

    Hi,

    If you add the new columns with the headers "SamAccountName", "proxyAddresses" and "mail" to the csv file you can do it like this

    $Groups = Import-CSV -path "C:\users\Name$\Temp\Grouptest.csv"  
    ForEach ($Object in $Groups)  
    {  
        $OldName = $Object.OldName  
        $NewName = $Object.NewName  
        Get-ADGroup $OldName | Set-ADGroup -Replace @{SamAccountName=$Object.SamAccountName;proxyAddresses=$Object.proxyAddresses;mail=$Object.mail}  
        Get-ADGroup $OldName | Rename-ADObject -NewName $NewName  
     }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.