Skip to content

Instantly share code, notes, and snippets.

@eguyd
Created June 16, 2019 03:21
Show Gist options
  • Save eguyd/b0632d90deff31c8e71d327c953a78bb to your computer and use it in GitHub Desktop.
Save eguyd/b0632d90deff31c8e71d327c953a78bb to your computer and use it in GitHub Desktop.
Addd users to AD using CSV bulk upload.
#
#AUTHOR: Guy Derenoncourt
#PROGRAM: MANAGE AD USER WIN SERVER 2016
#
#This Sample Code is provided for the purpose of illustration "AS IS" WITHOUT WARRANTY OF ANY KIND.
#
#
###########################################################################
#
#
# LETS IMPORT NECESSARY MODULES
get-module -listavailable
import-module -activedirectory
get-command -module activedirectory | more
# IMPORT CSV FILE
Import-CSV "C:\ADPS\users.csv" |
New-ADUser -Enabled $True -AccountPassword $(ConvertTo-SecureString "notapassword" -AsPlainText -Force)
#DYNAMICALLY CREATE USERS
Get-ADUser -LDAPFilter "(department=*)" -Property Department |
Sort-Object Department -Unique | Select-Object Department |
ForEach-Object {New-ADOrganizationalUnit $_.Department -ProtectedFromAccidentalDeletion $false}
#MOVE ALL USERS TO RESPECTIVE DEPARTMENT NAME
$rootDN = (Get-ADDomain).DistinguishedName
Get-ADUser -LDAPFilter "(department=*)" -Property Department, DistinguishedName |
ForEach-Object {Move-ADObject -Identity $_.Distinguishedname -Targetpath "OU=$($_.Department),$rootDN"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment