Batch update All OU

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?

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:

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

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

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

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

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

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