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

I spoke at a conference a couple of months ago about Active Directory management and free tools available to help with Active Directory management. One of the attendees from the presentation recently asked for some guidance using PowerShell to perform a bulk update of AD user information.

Web Active Directory’s PeopleNexus product allows you to bulk provision, de-provision, and update users from your data sources without scripting by allowing you to use a configurable administrative user interface. You can perform these updates ad-hoc from the user interface or hands free using provided processes and REST services that can be scheduled to run with whatever frequency you want. For more information about this product, visit the  People Nexus product page.

The simple PowerShell snippet here 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. Refer to the documentation references below the script for more information about the specific cmdlets and how to use the ActiveDirectory module for PowerShell.

PowerShell Script to Bulk Update Active Directory User Information

# 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.

Handy ActiveDirectory Module Cmdlet References

Comments are closed.

Sign in
Forgot password?
Sign up

(*) Required fields

I agree with OptimaSales Terms & Privacy Policy