Link to home
Start Free TrialLog in
Avatar of markc56
markc56Flag for United States of America

asked on

Powershell script to change an attribute for all active directory users

I need to create a script that will rename all active directory users attritbute (cn). Just for clarification this is the the CN= of the DistinguishedName field ( I briefly mixed this up). Mainly, I need the command to change this field in AD.
Avatar of SubSun
SubSun
Flag of India image

You can use Rename-ADObject to change the name of the object (With windows 2008 R2 DC and above)..
Ref : http://ss64.com/ps/rename-adobject.html

If you can explain, what modification you need for the name then only we can suggest further.
cn, I believe it is stand for Contexts Name.

anyway what changes you would like to make by script?

like add some prefix or change it to match First Name Last Name?

would you please provide some detail regarding on it.

for instance,

you can do
example

get-aduser -id abc | set-aduser -replace @{cn="abc01"}
Avatar of markc56

ASKER

We have a secondary program for ticketing that we need to import users into from AD. In the cn field we not only have a name, but area of work and here is where the problem is. We are using a "/" between areas and the ticketing program will not recognize the "/", so we need to change it to a "-" or "_" which it does recognize.
do you have last name, first name as the CN?
Avatar of markc56

ASKER

Justin: When I tried running the command you listed (get-aduser -id abc | set-aduser -replace @{cn="abc01"}) I found out you cannot make a change. It errors out referencing a system file error. Thanks for help.
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of markc56

ASKER

This works exactly as I needed.  Thanks!