Solved

Powershell script to change an attribute for all active directory users

Posted on 2014-07-22
9
2,348 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
  • 3
  • 3
  • 2
9 Comments
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 14

Expert Comment

by:Justin Yeung
Comment Utility
do you have last name, first name as the CN?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 14

Expert Comment

by:Justin Yeung
Comment Utility
0
 
LVL 3

Author Comment

by:markc56
Comment Utility
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
Comment Utility
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
Comment Utility
This works exactly as I needed.  Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
A procedure for exporting installed hotfix details of remote computers using powershell
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now