Powershell – Bulk Set AD user description, department and title

To set User description, department and job title in Bulk you can use this script

Import-Module ActiveDirectory


$users = Import-Csv -Path C:\Temp\user-import.csv

foreach ($user in $users) {

Get-ADUser -Filter "userPrincipalName -eq '$($user.userPrincipalName)'" |Set-ADUser -description $($user.description) -department $($user.department) -title $($user.title)
Write-Host "Writing Data  to AD for User  $($user.userPrincipalName)" -ForegroundColor Yellow 

#Get-ADUser -Filter "userPrincipalName -eq '$($user.userPrincipalName)'" -Properties * -SearchBase "OU=Asia_Sales,dc=shellgeek,dc=com" |Set-ADUser -department $($user.department) -title $($user.title) 
}

You need to create a .csv file which has this format :

“userPrincipalName”,”description”,”department”,”title”
[email protected]”,”description 123″,”department 123″,”title 123″

Other handy commands :

Get-AdUser

#Export all ad users
Get-ADUser -Filter * -Properties * | Select-Object userPrincipalName, description ,department ,title | export-csv -path c:\temp\userexport.csv

#Get AD user properties
get-aduser -Filter {(userPrincipalName -eq "[email protected]")} -Properties * | select SAMAccountname, Description, Title, Company, @{Name='Manager';Expression={(Get-ADUser ($_.Manager)).SAMAccountname}}

#same as above but with the use of the identity instead of a filter
get-aduser -Identity poely99 -Properties * | select SAMAccountname, Description, Title, Company, @{Name='Manager';Expression={(Get-ADUser ($_.Manager)).SAMAccountname}}

Leave a Reply

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