Solved

Powershell script to change an attribute for all active directory users

Posted on 2014-07-22
9
2,397 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

813 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

8 Experts available now in Live!

Get 1:1 Help Now