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 1
  • 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!


 

Comments
  • Thanks

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