Skip to main content

Quick PowerShell script to update an AD attribute

# Import AD Module
Import-Module ActiveDirectory

# Import CSV into variable $userscsv
$users = Import-Csv -Path C:\Users\EXAMPLE\Documents\UpdateCompanyTest.csv

# Loop through CSV and update users if they 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 "OU=Employees,OU=Users,DC=EXAMPLE,DC=NET" | Set-ADUser -Company $($user.company)

}