This is the code submitted by @Erik Moreau ,corrected to update only those users whose spelling and/or capitalization of the "Office" property is not what is desired:
# Define the incorrect and correct office spellings
$incorrectOffice = "vienna, VA" # should be spelled exactly -- CAPITALIZATION DOESN'T MATTER!
$correctOffice = "Vienna, VA" # should be spelled correctly, WITH CORRECT CAPITALIZATION
if ($incorrectOffice -ceq $correctOffice){
Throw "Spelling and capitalization of both office strings is identical. This is wrong."
}
# Get all AD users with the office capitalized correctly OR incorrectly
# and update the office field
Get-ADUser -filter "Office -eq $incorrectspelling" -Properties Office |
Where-Object {$_.Office -cne $correctOffice} |
ForEach-Object{
Set-ADUser -Identity $_ -Office $correctOffice
Write-Host "Updated office field for user: $($_.SamAccountName)"
}
Write-Host "Office field update completed."