Skip to content

Instantly share code, notes, and snippets.

@kurtisdunn
Last active May 2, 2019 23:20
Show Gist options
  • Save kurtisdunn/06c4406d670a77c14909fe19d04ae51c to your computer and use it in GitHub Desktop.
Save kurtisdunn/06c4406d670a77c14909fe19d04ae51c to your computer and use it in GitHub Desktop.
active_directory.ps
  
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment