Bulk replace attributes for multiple users in Active Directory

Example 1: Change addresses for multiple users with a specific address

Here is a PowerShell script I used to replace the address for multiple users in Active Directory.

First it finds the specific users I want to change based on a search criteria. Then it sets the specified attributes for those users.

🛑⚠ Note: Be careful when using this script as it will apply changes. The -WhatIf option is added to avoid disasters. Remove -WhatIf only when you feel ready to apply the changes!

# Find enabled users in AD with city attribute equal to Shenzhen and replace the specified attributes with "......"

$users = Get-ADUser -SearchBase "OU=Users,OU=ABCompany,DC=abc,DC=local" -Filter {(city -like "Shenzhen") -And (Enabled -eq $true)}
foreach ($user in $users) {
Set-ADUser $user.samaccountname -city "......" -State "......" -Office "......" -streetaddress "......" -POBox "......" -Postalcode "......" -WhatIf
}

Of course you will have to replace ...... with the actual value you want to set to the users.