# Modify ACtive directory groups

**URL:** https://forums.powershell.org/t/modify-active-directory-groups/16420
**Category:** PowerShell Help
**Created:** [May 4, 2021, 5:29am UTC](https://forums.powershell.org/t/modify-active-directory-groups/16420 "2021-05-04T05:29:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![admin557](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/admin557/32/1275_2.png) [@admin557](https://forums.powershell.org/u/admin557)
#### Post date: [May 4, 2021, 5:29am UTC](https://forums.powershell.org/t/modify-active-directory-groups/16420/1 "2021-05-04T05:29:17Z")

</div>

$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 change group name, but not getting clue to change other attributes like SamaccontName, Proxyaddress, Emailaddress

---

<div class="post-metadata">

### Author: ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)
#### Post date: [May 4, 2021, 7:00am UTC](https://forums.powershell.org/t/modify-active-directory-groups/16420/2 "2021-05-04T07:00:22Z")

</div>

Admin557,  
Welcome to the forums.

Could you please format your code as code here in the forum? Thanks in advance.

Most of the time when you have cmdlets with the verb “`Get`” like `Get-ADGroup` you also have cmdlets with the verb “`Set`” like “`Set-ADGroup`”. 😉

> **[Set-ADGroup (ActiveDirectory)](https://docs.microsoft.com/en-us/powershell/module/activedirectory/set-adgroup?view=windowsserver2019-ps)**
>
> Use this topic to help manage Windows and Windows Server technologies with Windows PowerShell.

Please read the help completely including the examples to learn how to use it.

---

<div class="post-metadata">

### Author: ![admin557](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/admin557/32/1275_2.png) [@admin557](https://forums.powershell.org/u/admin557)
#### Post date: [May 4, 2021, 7:55am UTC](https://forums.powershell.org/t/modify-active-directory-groups/16420/3 "2021-05-04T07:55:04Z")

</div>

I followed article and able to create below script, but No luck. Any suggestion.

$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 }

---

<div class="post-metadata">

### Author: ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)
#### Post date: [May 4, 2021, 8:08am UTC](https://forums.powershell.org/t/modify-active-directory-groups/16420/4 "2021-05-04T08:08:32Z")

</div>

> [@admin557](#):
>
> but No luck

“_ **No luck** _” is usually not a helpful description of what’s happening. Don’t you get errors when you run this code? If you get error messages you should post them here completely (formatted as code as well please).

> [@admin557](#):
>
> Any suggestion.

I have two. 😉

1. Format your code as code.
2. Use curly braces around the script block of your foreach loop. 😉

And BTW: To set the sAMAccountName you can use the parameter `-SamAccountName` directly.

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:26pm UTC](https://forums.powershell.org/t/modify-active-directory-groups/16420/5 "2024-05-16T20:26:31Z")

</div>


