I have a problem with a simple script. I need to copy attributes (STATE to CITY) on all users in my OU. I found this script, but there is an error somewhere.
Could someone help me with this?
Get-ADUser -Filter * -SearchBase "MY OU" -Properties city, state |
ForEach-Object {
Set-ADObject -Identity $_.DistinguishedName ` -Replace @{city=$($_.state)}
}
Command to grab all users where state has a value (a precaution to avoid attempting to use null values which Replace will not accept) and write that value into the city attribute (L)
PS> Get-ADUser -SearchBase "ou=test accounts,dc=domain,dc=ccTLD" -LDAPFilter '(st=*)' -Properties city, state | Select-Object * | ForEach-Object {Set-ADObject -Identity $_.DistinguishedName ` -Replace @{l=$($_.state)}}