Simple PowerShell Script to Bulk Update or Modify Active Directory User Attributes

PowerShell Script to Bulk Update Active Directory User Information

The simple PowerShell script below uses the Get-ADUser cmdlet from the ActiveDirectory PowerShell module to retrieve all the users in one OU and then iterate the users to set a couple of AD properties.

# Get all users in the Finance OU.
$FinanceUsers = Get-ADUser -Filter * -SearchBase "OU=Finance,OU=UserAccounts,DC=FABRIKAM,DC=COM"
# Iterate the users and update the department and title attributes in AD.
foreach($FinanceUser in $FinanceUsers)
{
    # Update properties.
    $FinanceUser.department = "Finance"
    $FinanceUser.title = "Analyst 1"   
    # Update the user data in AD using the Instance parameter of Set-ADUser.
    Set-ADUser -Instance $FinanceUser
}

The example uses the Instance parameter of Set-ADUser to update each user in the OU. The parameter allows any modifications made to the ADUser object to go to the corresponding Active Directory object while only updating object properties that have changed.

Looking for solutions to automate Active Directory tasks?

Web Active Directory offers a variety of products to automate Active Directory tasks like provisioning, deprovisioning, updates and password resets. Learn More.