################################# # Script to update attributes for Active Directory users # # Script by SLCSysAdmin - please credit and link! # http://slcsysadmin.blogspot.com # # NOTE: be sure that "Active Directory Module for Windows PowerShell" # is loaded in PowerShell before running ################################# $dataSource=import-csv "AccountList.csv" foreach($dataRecord in $datasource) { $sAMAccountName=$dataRecord.sAMAccountName # List of attributes to update $employeeType=$dataRecord.employeeType $department=$dataRecord.department # NOTE: For the following item, the extra code is necessary because "employeeType" is not # one of the "commonly used property values" as found in the following list: # http://technet.microsoft.com/en-us/library/ee617215.aspx Get-ADUser -Identity $sAMAccountName -Properties employeeType | Set-ADUser -Replace @{employeeType=$employeeType} # NOTE: The following is much simpler because "department" is one of the common property values Get-ADUser -Identity $sAMAccountName | Set-ADUser -Department $department }
It is worth mentioning for first-timers that your column names in your CSV file need to match what you're doing in your script. For example, my CSV file would look like this for use with the code above:
sAMAccountName,employeeType,department
usernameA,1234,IS
usernameB,9876,BB
...
usernameZ,3476,ZZ
When the request comes in to update different attributes, make the necessary changes to the script and make sure you update your columns in your CSV file accordingly. Enjoy, and feel free to hit me with your comments or suggestions!
Awesome Script!! It worked greatly :)
ReplyDeleteExcellent. Thanks.
ReplyDeleteVery Very usefull. Thanks!!!
ReplyDeleteWorking welll! Thanks
ReplyDelete