Skip to content

Instantly share code, notes, and snippets.

@bbkane
Created March 20, 2020 20:35
Show Gist options
  • Save bbkane/bd1f32e04bf9d6a6d5cb6ab286d19af6 to your computer and use it in GitHub Desktop.
Save bbkane/bd1f32e04bf9d6a6d5cb6ab286d19af6 to your computer and use it in GitHub Desktop.
Change AD Users from Powershell
userid first_name
bkane Benjamin
cmferg Christian
$ python3 print_powershell.py
Get-AdUser 'bkane' | Set-AdUser -GivenName 'Benjamin'
Get-AdUser 'cmferg' | Set-AdUser -GivenName 'Christian'
import csv
# Something like this - modify for your fields
with open('names.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
# read from csv
userid = row['userid']
first_name = row['first_name']
# put into powershell command - note how I'm quoting all data (see output.txt)
psh_cmd = f"Get-AdUser '{userid}' | Set-AdUser -GivenName '{first_name}'"
print(psh_cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment