Randomly Expressed

About

Welcome to my blog “randomly expressed”. I created this website to publish helpful tips. It’s mainly technology driven, but I will blog about other topics. I am a Unix sysadmin that is always looking to learn new things. My goal is to be able to share knowledge that others may find useful. xkcd.com

Continue Reading »

Contact

Connect With US

Connect with us on the following social networking sites.

Most Popular Posts.

Add Some Content to This Area

You should either deactivate this panel on the Theme Settings page, or add some content via the Widgets page in your WordPress dashboard.

Bulk changes to AD accounts

By on February 2, 2017 in Technology with No Comments

A Window’s batch script for making changes to AD user account attributes in bulk.

# Import AD Module
Import-Module ActiveDirectory
 
write-Host 'Starting to update AD Attributes.......' -NoNewline -ForegroundColor Yellow
# Import CSV into variable $users
 
$users = Import-Csv -Path C:\Users\admin\Documents\users.csv
# Loop through CSV and update users if the exist in CVS file
 
foreach ($user in $users) {
#Search in specified OU and Update existing attributes
Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "DC=corp,DC=aol,DC=com" | Set-ADUser -Department $($user.Department)
}
 
Write-Host 'done!' -ForegroundColor Green

The users.csv file contains the following. It is where you define the changes you want to make to the users.

SamAccountName,Department
John.Doe,HR
Mary.Jane,Finance
Peter.Parker,Animations

Facebook Comments

Tagged With: ,

Post a Comment

Your email address will not be published. Required fields are marked *

Top