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