Skip to content

Instantly share code, notes, and snippets.

@rwindegger
Created September 30, 2016 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwindegger/cf7d01eea78827cd7f0da7cc6f5c74c1 to your computer and use it in GitHub Desktop.
Save rwindegger/cf7d01eea78827cd7f0da7cc6f5c74c1 to your computer and use it in GitHub Desktop.
This file is used to create the active directory accounts based on a users.txt input file.
Import-Module ActiveDirectory
$path = Split-Path -parent $MyInvocation.MyCommand.Definition
$importPath = $path + "users.txt"
# EDIT to fit your domain
$domain = "@yourdomain.local"
# EDIT to fit the ou you want to create your users in - make shure it exists
$location = "OU=SharePoint,OU=Service Users,OU=Users,DC=yourdomain,DC=local"
# EDIT to fit your password policy - otherwise creation will fail
$initialPass = ConvertTo-SecureString -AsPlainText "Pass@Word1" -force
Import-CSV $importPath | ForEach-Object {
$sam = $_.Username.ToLower()
Try { $exists = Get-ADUser -LDAPFilter "(sAMAccountName=$sam)" }
Catch { }
If(!$exists)
{
$upn = $sam + $domain
New-ADUser $_.Name -SamAccountName $sam -Path $location -DisplayName $_.Name -UserPrincipalName $upn -AccountPassword $initialPass
$user = Get-ADUser -LDAPFilter "(sAMAccountName=$sam)"
Enable-ADAccount -Identity $user
Unlock-ADAccount -Identity $user
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment