Intro

A PowerShell script to create AD users.

Code

###########################
# author : shebangthedolphins.net
# version : 1.0
# date : 2018.06
# role : Create AD users from a list
# other : Tested on Windows 2016 Server
# updates :
#       - 1.X (x/x/xxxx) :    

$users = New-Object System.Collections.ArrayList
[void] $users.AddRange( ("Firstname01 Name01","Firstname02 Name02","Firstname03 Name03"))

Foreach ($user in $users)
{
    Write-Host "My user : $user"
    $pos = $user.IndexOf(" ")
    $first_name = $user.Substring(0, $pos).ToLower()
    $name = $user.Substring($pos+1).ToLower()

    $first_name_ = "$($first_name.substring(0,1).ToUpper())$($first_name.Substring(1))"
    $name_ = "$($name.substring(0,1).ToUpper())$($name.Substring(1))"
    $first_name__ = $first_name.ToUpper()
    $name__ = $name.ToUpper()

    Write-Host "first_name : $first_name"
    Write-Host "name : $name"

    Write-Host "First_name : $First_name_"
    Write-Host "Name : $Nom_"

    Write-Host "FIRSTNAME : $FIRSTNAME__"
    Write-Host "NAME : $NAME__"


    #Write-Host "First_name : $($first_name.substring(0,1).ToUpper())$($first_name.Substring(1))"
    #Write-Host "Nom : $($name.substring(0,1).ToUpper())$($name.Substring(1))"
 
    #Write-Host "FIRSTNAME :" $first_name.ToUpper()
    #Write-Host "NAME :" $name.ToUpper()

    New-ADUser -Name "$($first_name_) $($name__)" -GivenName $first_name_ -Surname $name__ -SamAccountName "$($first_name).$($name)" -UserPrincipalName "$($first_name).$($name)@domain-name.priv" -AccountPassword (ConvertTo-SecureString "UserPassword" -AsPlainText -Force) -PassThru | Enable-ADAccount
}

Licence Creative Commons
This websitehttp://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :