Created
March 20, 2020 20:35
-
-
Save bbkane/bd1f32e04bf9d6a6d5cb6ab286d19af6 to your computer and use it in GitHub Desktop.
Change AD Users from Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
userid | first_name | |
---|---|---|
bkane | Benjamin | |
cmferg | Christian |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3 print_powershell.py | |
Get-AdUser 'bkane' | Set-AdUser -GivenName 'Benjamin' | |
Get-AdUser 'cmferg' | Set-AdUser -GivenName 'Christian' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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