Powershell - attributes_copy.ps1

The command below searches for [email protected], get two attributes Title and sAMAccountName and inserts the content of sAMAccountName on the Title attribute. The “First 1” limits the results in case of LDAPFilter *:

Get-ADUser -LDAPFilter '(sAMAccountName=x)' -Properties Title, sAMAccountName | Select-Object * -First 1 | ForEach-Object { Set-ADObject -Identity $_.DistinguishedName ` -Replace @{Title = $($_.sAMAccountName) } }

Same as above but replacing every single user, title = sAMAccountName:

Get-ADUser -LDAPFilter '(sAMAccountName=*)' -Properties Title, sAMAccountName | ForEach-Object { Set-ADObject -Identity $_.DistinguishedName ` -Replace @{Title = $($_.sAMAccountName) } }

Sources:

  • https://blogs.technet.microsoft.com/ashleymcglone/2012/07/23/how-to-copy-ad-user-attributes-to-another-field-with-powershell/