PowerShell Script for Automated Update of Active Directory User Job Titles and Company

Опубликовано: 10 Июнь 2026
на канале: Global IT Gurukul
417
4

SV Example (users.csv):
SamAccountName,JobTitle,Office

PowerShell Script
Import Active Directory module
Import-Module ActiveDirectory

Path to the CSV file
$csvPath = "C:\Path\To\Your\users.csv"

Import users from the CSV file
$users = Import-Csv -Path $csvPath

Loop through each user from the CSV and update their attributes
foreach ($user in $users) {
$samAccountName = $user.SamAccountName
$jobTitle = $user.JobTitle
$office = $user.Office

Get the user from AD
$adUser = Get-ADUser -Filter { SamAccountName -eq $samAccountName }

if ($adUser) {
Update the Job Title and Office attributes
Set-ADUser -Identity $adUser -Title $jobTitle -Office $office
Write-Host "Updated Job Title and Office for $samAccountName to '$jobTitle' and '$office'"
} else {
Write-Host "User with SamAccountName $samAccountName not found."
}
}