I need to reconcile the displayName
and CN
attributes to the givenName
and surName
fields in AD.
Is it possible to take givenName
and surName
and rename both the displayName
and CN
using Powershell?
I need to reconcile the displayName
and CN
attributes to the givenName
and surName
fields in AD.
Is it possible to take givenName
and surName
and rename both the displayName
and CN
using Powershell?
Powershell really shines for clean-up tasks like this.
Caveats:
Trim()
ing thegivenName
andsurName
to remove leading/trailing spaces. We commit these two back to the account, as well as correctingdisplayName
andcn
.-Filter
inGet-ADUser
to only gather the users you want. The*
will grab everyone in the domain, including built-ins, admins, etc. This probably isn't what you want. :)Where-Object
portion of theforeach
will skip user objects that do not have both agivenName
andsurName
attribute.-PassThru
to the end of theRename-ADObject
line and the object will be passed back to you.