Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement