Skip to content

Instantly share code, notes, and snippets.

@mike-myers-tob
Created November 25, 2020 23:38
Show Gist options
  • Save mike-myers-tob/2adab51cafa3b64506cc342c6d0ea284 to your computer and use it in GitHub Desktop.
Save mike-myers-tob/2adab51cafa3b64506cc342c6d0ea284 to your computer and use it in GitHub Desktop.
# New-ADUser cmdlet is included in the Active Directory PowerShell module.
#
# Prereuquisite install:
#
# Windows 10 -> Go to Manage optional features in Settings.
# Click Add a feature to see the list of available RSAT tools.
# Install "RSAT: Active Directory Domain Services and Lightweight
# Directory Services Tools".
# You can only install RSAT on Professional or Enterprise editions
# of the Windows client operating system.
# Windows Server 2016 -> Server Manager -> Add Roles and Features -> Features
# -> Remote Server Administration Tools
#
# Requires you to have Domain administrator access. Quick and dirty steps to set up
# Windows Server 2016 as a Domain Controller running Active Directory Web Services:
#
# a) Manage, Local Server, Add Roles & Features, Active Directory Domain Services, Next next next Install.
# b) Flag -> Promote this server to a domain controller. For root domain name I
# chose "trailofbit.test". Enter a DSRM password of your choosing. Ignore the warning about
# DNS server delegation. Verify "TRAILOFBIT" is the NetBIOS domain name. Okay. Accept
# default paths. Next. Ignore warnings, click Install.
# c) When Windows restarts, log in you may need to fix the DNS server IP. Windows may set
# its DNS server IP to localhost 127.0.0.1 at this point. Verify internet access, e.g.
# with Internet Explorer. Then you can proceed.
#
# 1) The users CSV file is here: https://docs.google.com/spreadsheets/d/1yPr_eutYWxUZX5ZhygvaMwi15aLVsjWNs275kQI4Q9A/edit?usp=sharing
# 2) Download it as a CSV, rename it to Users.csv in the directory of this script. Cut it to however many rows you need to test.
# 3) Run this script in an Administrator PowerShell prompt.
Import-Module ActiveDirectory
# Get-Command New-ADUser -Syntax
$dataSource=import-csv "Users10k.csv"
foreach($dataRecord in $dataSource) {
$displayName = $dataRecord.FirstName + " " + $dataRecord.LastName
# User accounts, by default, are created without a password, and the account
# is disabled unless it is enabled (Enable-ADAccount and Set-ADAccountPassword)
New-ADUser -Name $dataRecord.FirstName -DisplayName $displayName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment