# Batch update All OU

**URL:** <https://forums.powershell.org/t/batch-update-all-ou/19011>\
**Category:** PowerShell Help\
**Created:** [April 4, 2022, 9:10am UTC](https://forums.powershell.org/t/batch-update-all-ou/19011 "2022-04-04T09:10:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qadmin](https://avatars.discourse-cdn.com/v4/letter/q/3d9bf3/32.png) [@Qadmin](https://forums.powershell.org/u/Qadmin)\
**Post date:** [April 4, 2022, 9:10am UTC](https://forums.powershell.org/t/batch-update-all-ou/19011/1 "2022-04-04T09:10:08Z")

</div>

Hi

When I need to clear an attribute i use this:

$ThisUser = Get-ADUser -Identity xxpenor -Properties extensionAttribute1  
Set-ADUser –Identity $ThisUser -Clear “extensionattribute1”

This clear attribute 1

When i need to clear or update all users in an OU.

I tryed to use:  
Get-ADUser -Filter 'Name -like “_"’ -SearchBase “OU=Users,OU=xx my town, OU=xx xxx,DC=xxx,DC=xxx,DC=se” -Properties extensionAttribute7  
Set-ADUser -Identity "_” -Clear “extensionAttribute7”  
Get-ADUser -Filter \* -SearchBase “OU=Users,OU=xx my town, OU=xx xxx,DC=xxx,DC=xxx,DC=se” -Properties extensionAttribute7  
Set-ADUser -Identity _._ -Clear “extensionAttribute7”

What i whant i to edit/clear en attribute for all user at once.

How can i do that?

---

<div class="post-metadata">

**Author:** ![laage](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/laage/32/43_2.png) [@laage](https://forums.powershell.org/u/laage)\
**Post date:** [April 4, 2022, 9:35am UTC](https://forums.powershell.org/t/batch-update-all-ou/19011/2 "2022-04-04T09:35:18Z")

</div>

Hello Qadmin,

Welcome…  
When adding code to a post please use the \</\> (Preformatted text) button to make it easier to read and copy.

If I understand you correctly, one way of doing what you want would be the following:

```auto
$OUsers = Get-ADUser -Filter * -SearchBase “OU=Users,OU=xx my town, OU=xx xxx,DC=xxx,DC=xxx,DC=se”

foreach ($user in $OUsers) {
    Set-ADUser –Identity $user -Clear “extensionattribute1” -WhatIf
}

```

I added the `-WhatIf` parameter inside the foreach-block so you see what the `Set-ADUser` cmdlet intends to do.  
Once you’re satisfied with the results you can remove `-WhatIf` and perform the change.

---

<div class="post-metadata">

**Author:** ![Qadmin](https://avatars.discourse-cdn.com/v4/letter/q/3d9bf3/32.png) [@Qadmin](https://forums.powershell.org/u/Qadmin)\
**Post date:** [April 4, 2022, 10:20am UTC](https://forums.powershell.org/t/batch-update-all-ou/19011/3 "2022-04-04T10:20:13Z")

</div>

Hi

Sorry, can’t follw the code

Could you write it al like i need to write it in PS?

Hämta [Outlook för Android](https://aka.ms/AAb9ysg)

---

<div class="post-metadata">

**Author:** ![laage](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/laage/32/43_2.png) [@laage](https://forums.powershell.org/u/laage)\
**Post date:** [April 4, 2022, 10:50am UTC](https://forums.powershell.org/t/batch-update-all-ou/19011/4 "2022-04-04T10:50:32Z")

</div>

This is how you write it in PS.  
You can write the foreach-loop on one line, but that does not change anything:

```auto
$OUsers = Get-ADUser -Filter * -SearchBase “OU=Users,OU=xx my town, OU=xx xxx,DC=xxx,DC=xxx,DC=se”

foreach ($user in $OUsers) { Set-ADUser –Identity $user -Clear “extensionattribute1” -WhatIf }

```

And as I said before, the `-WhatIf` is to make sure that you don’t do anything irreversible. Once you see that the command applies to the users you want to modify you remove it from the line.

---

<div class="post-metadata">

**Author:** ![Qadmin](https://avatars.discourse-cdn.com/v4/letter/q/3d9bf3/32.png) [@Qadmin](https://forums.powershell.org/u/Qadmin)\
**Post date:** [April 4, 2022, 10:58am UTC](https://forums.powershell.org/t/batch-update-all-ou/19011/5 "2022-04-04T10:58:13Z")

</div>

Great. And when i wnat to edit or add? What sh  
uld be then?

---

<div class="post-metadata">

**Author:** ![laage](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/laage/32/43_2.png) [@laage](https://forums.powershell.org/u/laage)\
**Post date:** [April 4, 2022, 11:25am UTC](https://forums.powershell.org/t/batch-update-all-ou/19011/6 "2022-04-04T11:25:12Z")

</div>

Edit or add what exactly?  
The command(s) we’ve talked about here or editing/adding users in general?

---

<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:18pm UTC](https://forums.powershell.org/t/batch-update-all-ou/19011/7 "2024-05-16T20:18:07Z")

</div>

Closed on May 16, 2024, 8:18pm UTC


