Musings on the splendour of PowerShell Active Directory Bulk User Modification - PoSh Chap - Site Home - TechNet Blogs

PoSh Chap

Musings on the splendour of PowerShell

Active Directory Bulk User Modification

Active Directory Bulk User Modification

  • Comments 4
  • Likes

An old favourite! This is what automation is all about: making the tedious and the long-winded incredibly easy, and, dare I say, joyous!

Your HR department gives you a dump of user names with email addresses and phone numbers to be updated in Active Directory.

The dump is in the form of a CSV file and looks a something like this:


Currently, the users from the dump don't have those values set in Active DIrectory:


Now, let's use PowerShell to read in the CSV file and make some bulk updates...

Import-CSV .\HR_Update.csv |

ForEach-Object {Get-ADUser -Filter "Name -eq `"$($_.Name)`"" | Set-ADUser -EmailAddress $_.Email -OfficePhone $_.Phone}


First, use the Import-CSV cmdlet to read in the contents of the HR dump file.

Next, the ForEach-Object cmdlet executes the code between the curly braces for each line from the CSV file sent down the pipeline.

The code uses Get-ADUser with a filter that matches the 'Name' from the CSV file column to the name of a user in Active Directory.

If a match is found, the resultant object is piped into the Set-ADUser cmdlet. The Set-ADUser cmdlet updated the user's email address and office phone number based on the current entries from the 'Email' and 'Phone' columns of the CSV file.


Let's use PowerShell to check the updates out:

Get-ADUser -Filter * -SearchBase "OU=Word Smiths,OU=User Accounts,DC=fabrikam,DC=com" -Properties EmailAddress,OfficePhone |

Select-Object Name,EmailAddress,OfficePhone



Well, that's it for now. I hope you enjoyed my take on this stalwart of elementary automation!


  • Thanks

  • Thks! and when the field is empty? o ",,"

  • seems like there are some issues with using -country switch for updating the Combo Box. After spending some time I found out that the ADAC uses a syntax like: -Replace:@{"c"="GB";"co"="United Kingdom";"countryCode"="826"}. I wanted to update the country to United Kingdom with the -country switch with errors

  • I tried this but it kicks out question for identity every time i run it

    my code
    import-module ActiveDirectory
    import-CSV C:\Users\Administrator\Desktop\DC01.csv
    $OU = "OU=Vworkspace,DC=remote,DC=sojab0on,DC=nl"
    $Users = Get-ADUser -Filter * -SearchBase $OU

    ForEach-Object {Set-ADUser -Company $_.Bedrijf -OfficePhone $_.telephonenumber -MobilePhone $_.Mobiel -Department $_.Afdeling}

    And whrn i fill in an user identity it looks normal but it does noet change the fields

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment