Active Directory Bulk User Modification

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!