A script by Jeff Stein
The script entitled "Run-ADusercreation" will perform the necessary steps to create an active directory user account for each user contained in a CSV file. The script is designed for the Microsoft Windows operating system, leveraging PowerShell 4.0 and above.
This script is offered 'as is' with no warranty. While it has been tested and verified to work in my environment, it is recommended that you test this script in a test environment before utilizing in your own production environment.
To get started download the files listed in the resource section and save the Run-ADusercreation.txt as a .ps1 file. It should be extracted to the desktop of the Windows machine where the script will run from. The CSV template file should be placed in the same directory. The Active Directory module should be installed on the machine for the script to run properly. Once extracted, the Run-ADusercreation.ps1 file can be right-clicked and "Run with PowerShell" can be selected. It is recommended that this is an account that has administrator privileges. Alternatively, PowerShell can be manually opened on the system and the terminal navigated to the appropriate directory where the script is located and executed from there. With either option, it is recommended the action to run the script is done with an account that has administrator privileges.
The script will create an active directory user account for each user added to the provided CSV file. You can see an sample of the code below:
$csvFilename = ".\users.csv"
$csv = Import-Csv $csvFilename -Header @("FirstName","LastName","Username","Title","Department","Manager") | select -Skip 1
After importing the CSV file and stripping the template header from it the commands are run to provision each account using a foreach loop generating the following fields:
foreach ($line in $csv) {
New-ADUser -Name $line.FirstName+$line.LastName -DisplayName $line.FirstName+$line.LastName -GivenName $line$FirstName -Surname $line$LastName -SamAccountName $line.$Username -Title $line.$Title -Department $line.$Department -Manager $line.$Manager
}
Security Vulnerabilities IDS/IPS Malware Policies PowerShell Python Splunk Cloud Script PKI