Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell script to change an attribute for all active directory users

Posted on 2014-07-22
9
Medium Priority
?
2,646 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
Independent Software Vendors: 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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 …
Suggested Courses

885 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