PowerShell Changes User information

Source: Internet
Author: User
Tags samaccountname

PowerShell's ad-related commands ash works well, beans took a list from HR this morning and needed to update all AD user positions and departmental information. This list of thousands of people, certainly cannot be manually modified, a simple few lines of script can be quickly resolved. The basic method is to search for the user through Get-aduser, and then use the Set-aduser command to modify the line.


The list format is as follows: HR code, first name, last name, join date, position, department, etc. Because the ghost is accustomed to marry after change the name, all directly through the DisplayName search many people cannot find. However, sAMAccountName generally does not change, the company's name is the first name of the initials + the last name intial+.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/E4/wKiom1U5e5KyG9gzAALpk1mNVis542.jpg "title=" screen Shot 2015-04-24 at 9.06.05 am.png "alt=" Wkiom1u5e5kyg9gzaalpk1mnvis542.jpg "/>


How to change to this sAMAccountName, very simple, using the Split function to separate reorganization on the line


Like what:

$a =get-content ' C:\employee.csv ' foreach ($b in $a) {$c = $b. Split (",") $init = $c [1][0] $lastname = $c [2] $shortnama E= $init + $lastname}


Once you get the sAMAccountName, it's simple, in the Foreach Loop, use Get-aduser to search, and then set-aduser modify it. Can be written as a line, through the pipeline transmission, can also be written separately.


Like what:

$user =get-aduser $shortnameif ($user-eq $null) {$b >> c:/temp/error.csv}else{$user. sAMAccountName Set-adu Ser $user. Samaccountname-replace @{title= $c [4];d epartment-$c [5]}}


So you can modify the

This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1637787

PowerShell Changes User information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.