0

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)}
    }
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Artur
  • 3
  • 1
  • *"but there is an error somewhere"* "Error" meaning what exactly? Are you getting an error? What does it say? Where does it occur? – Ansgar Wiechers Oct 02 '18 at 23:04

1 Answers1

0

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)}}
LisaJ
  • 1,666
  • 1
  • 12
  • 18