Solved

Powershell script to change an attribute for all active directory users

Posted on 2014-07-22
9
2,532 Views
Last Modified: 2014-07-26
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.
0
Comment
Question by:markc56
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
9 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 40211957
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.
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40212105
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"}
0
 
LVL 3

Author Comment

by:markc56
ID: 40212226
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40212317
do you have last name, first name as the CN?
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40212456
0
 
LVL 3

Author Comment

by:markc56
ID: 40212781
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.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40213098
CN and name of the object will be same.. Following cod will work for you. It will replace all the "/" in name with "-"
Get-ADUser -Filter * | ?{$_.Name -match "/"} | % {
$User = $_
  $User | Rename-ADObject -Newname $($User.Name -replace "/","-")
}

Open in new window

If you want to run it against a OU the use -SearchBase parameter..
Get-ADUser -SearchBase "OU=Users,OU=HQ,DC=Max,DC=com" -Filter * | ?{$_.Name -match "/"} | % {

Open in new window

0
 
LVL 3

Author Closing Comment

by:markc56
ID: 40221728
This works exactly as I needed.  Thanks!
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question