Bulk Import Active Directory User Properties with Windows PowerShell

recently i had the impulse to populate existing ad user object property fields with phone numbers, titles, companies, and office; however, i wanted to use powershell to bulk import instead of the old ldifde method or manual labor. it was actually quite easy, but it does require some time massaging the csv file in excel.

  • first, export a csv containing the users and fields you want to update (it will be our template). our anchor is going to be the sid because it is guaranteed to be unique across the forest.

 

get-adgroupmember "usergroup" | get-aduser -properties samaccountname, name, sid, telephonenumber, mobile, title, company, physicaldeliveryofficename | select-object samaccountname, name, sid, telephonenumber, mobile, title, company, physicaldeliveryofficename | export-csv users-to-update.csv -notypeinformation

 

  • open that file up in excel and start populating your blank columns. feel free to sort it however you like.

  • now the fun part. it’s time to import our populated csv file back into active directory. the set-aduser cmdlet will use the replace switch so that data will be replaced if it already exists. remember, the identity ($_.sid) is our anchor which will match the csv data to the ad user object.
import-csv -path "users-to-update.csv" | foreach-object {set-aduser -identity $($_.sid) -replace @{telephonenumber=$($_.telephonenumber); mobile=$($_.mobile); title=$($_.title); company=$($_.company); physicaldeliveryofficename=$($_.physicaldeliveryofficename)}}

since you’ve saved so much time updating your user objects, you can go back to playing galaga (^_^))))))))…

Share
Disqus Comments Loading...

Recent Posts

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

May 14, 2019 8:22 am 08:22

Change Grub Default Boot Entry on Linux Mint

i'm dual booting windows and linux mint on my laptop. the grub default is to boot into linux mint, however… Read More

April 23, 2019 7:45 pm 19:45

How to Reset Secure Channel On Active Directory Domain Controller

when you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am 08:14

Run SystemD Script Before System Shutdown

for the sheer hell of it, a few weeks ago i wanted to see if i could properly and successfully… Read More

April 20, 2019 10:14 am 10:14

Learn Systemctl Usage to Manage Systemd Service in Linux

systemd is new service manager for linux. it's a replacement for all previous init systems (sysv/sysvinit & ubuntu's upstart) and… Read More

April 20, 2019 7:55 am 07:55

Force Delete Windows Server DHCP Failover Relationship

if you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am 05:54