Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.