#Set the ExecutionPolicy to allow execution of scripts
Set-ExecutionPolicy Unrestricted
#Connect to your Domain Controller(DC)
#Change the value after the -ComputerName to your know DC
$session = New-PSSession -ComputerName "yourdomaincontroller" -Credential (Get-Credential)
Invoke-Command $session -Scriptblock { Import-Module ActiveDirectory }
Import-PSSession -Session $session -module ActiveDirectory
#Get a list of all domain controllers in your enviornment
Get-ADDomainController -Filter * | Select-Object name
Import-Csv "C:\ADUsers.csv" | ForEach-Object {
$upn = $_.SamAccountName + “@rebeladmin.com”
New-ADUser -Name $_.Name `
-GivenName $_."GivenName" `
-Surname $_."Surname" `
-SamAccountName $_."samAccountName" `
-UserPrincipalName $upn `
-Path $_."Path" `
-AccountPassword (ConvertTo-SecureString “Pa$$w0rd” -AsPlainText -force) -Enabled $true
}
#Sync active with O365
Start-ADSyncSyncCycle -PolicyType Delta