initial scripting and csv support
This commit is contained in:
57
user adding AD/user-add.ps1
Normal file
57
user adding AD/user-add.ps1
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Adds new Active Directory users from a CSV file.
|
||||||
|
.DESCRIPTION
|
||||||
|
Reads a CSV with user details and creates corresponding AD accounts.
|
||||||
|
.NOTES
|
||||||
|
Requires RSAT / ActiveDirectory module.
|
||||||
|
#>
|
||||||
|
Import-Module ActiveDirectory
|
||||||
|
|
||||||
|
# Path to CSV file
|
||||||
|
$csvPath = ".\users.csv"
|
||||||
|
|
||||||
|
# Import from CSV
|
||||||
|
$users = Import-Csv -Path $csvPath
|
||||||
|
|
||||||
|
foreach ($user in $users) {
|
||||||
|
$FirstName = $user.FirstName
|
||||||
|
$LastName = $user.LastName
|
||||||
|
$Username = $user.Username
|
||||||
|
$OU = $user.OU
|
||||||
|
$Password = (ConvertTo-SecureString $user.Password -AsPlainText -Force)
|
||||||
|
$Department = $user.Department
|
||||||
|
$Title = $user.Title
|
||||||
|
$DisplayName = "$FirstName $LastName"
|
||||||
|
$Email = "$Username@example.com"
|
||||||
|
|
||||||
|
# Check if user already exists
|
||||||
|
if (Get-ADUser -Filter {SamAccountName -eq $Username}) {
|
||||||
|
Write-Host "User $Username already exists, skipping..." -ForegroundColor Yellow
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create the user
|
||||||
|
try {
|
||||||
|
New-ADUser `
|
||||||
|
-SamAccountName $Username `
|
||||||
|
-UserPrincipalName $Email `
|
||||||
|
-Name $DisplayName `
|
||||||
|
-GivenName $FirstName `
|
||||||
|
-Surname $LastName `
|
||||||
|
-DisplayName $DisplayName `
|
||||||
|
-Path $OU `
|
||||||
|
-Department $Department `
|
||||||
|
-Title $Title `
|
||||||
|
-AccountPassword $Password `
|
||||||
|
-Enabled $true `
|
||||||
|
-ChangePasswordAtLogon $true
|
||||||
|
|
||||||
|
Write-Host "Created user: $DisplayName ($Username)" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Failed to create user $Username: $_" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "User import complete."
|
||||||
32
user adding AD/users.csv
Normal file
32
user adding AD/users.csv
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
FirstName,LastName,Username,OU,Password,Department,Title
|
||||||
|
Henriette,Fonteyn,hfonteyn,"OU=Directie,OU=Employees,DC=company,DC=local","P@ssword123","Directie","Algemeen Directeur"
|
||||||
|
Frank,Fonteyn,ffonteyn,"OU=Directie,OU=Employees,DC=company,DC=local","P@ssword123","Directie","Financieel Directeur"
|
||||||
|
Anja,de Groot,adegroot,"OU=Directie,OU=Employees,DC=company,DC=local","P@ssword123","Directie","Directie assistente"
|
||||||
|
Inge,Winsemius-Schut,iwinsemiusschut,"OU=HR,OU=Employees,DC=company,DC=local","P@ssword123","HR","Hoofd HR"
|
||||||
|
|
||||||
|
Antoon,van der Hoeven,avanderhoeven,"OU=BeheerOntwikkeling,OU=Employees,DC=company,DC=local","P@ssword123","Beheer & Ontwikkeling","Directeur Beheer & Ontwikkeling"
|
||||||
|
Freek,van der Plas,fvanderplas,"OU=BeheerOntwikkeling,OU=Employees,DC=company,DC=local","P@ssword123","Beheer & Ontwikkeling","Beheer & Ontwikkeling"
|
||||||
|
Fatima,Laroussi,flaroussi,"OU=BeheerOntwikkeling,OU=Employees,DC=company,DC=local","P@ssword123","M&A","M&A"
|
||||||
|
|
||||||
|
Norman,Jorgens,njorgens,"OU=Duitsland,OU=Employees,DC=company,DC=local","P@ssword123","Duitsland","Land directeur Duitsland"
|
||||||
|
Erica,Bessels,ebessels,"OU=Benelux,OU=Employees,DC=company,DC=local","P@ssword123","Benelux","Land directeur Benelux"
|
||||||
|
JeanJacques,Velo,jvelo,"OU=ZuidEuropa,OU=Employees,DC=company,DC=local","P@ssword123","Zuid-Europa","Land directeur Zuid-Europa"
|
||||||
|
|
||||||
|
Jelle,Snelle,jsnelle,"OU=SalesMarketing,OU=Employees,DC=company,DC=local","P@ssword123","Sales & Marketing","Manager Sales & Marketing"
|
||||||
|
Cheng,Fui,cfui,"OU=SalesMarketing,OU=Employees,DC=company,DC=local","P@ssword123","Sales & Marketing","Sales"
|
||||||
|
|
||||||
|
Harrie,Makers,hmakers,"OU=Operations,OU=Employees,DC=company,DC=local","P@ssword123","Operations","Operations Manager"
|
||||||
|
Eric,de Knutselaar,edeknutselaar,"OU=Operations,OU=Employees,DC=company,DC=local","P@ssword123","Technische Dienst","Technische dienst"
|
||||||
|
Piet,Poester,ppoester,"OU=Operations,OU=Employees,DC=company,DC=local","P@ssword123","Schoonmaak","Schoonmaak"
|
||||||
|
|
||||||
|
Francien,de Kok,fdekok,"OU=FoodBeverages,OU=Employees,DC=company,DC=local","P@ssword123","Food & Beverages","Manager Food & Beverages"
|
||||||
|
Mohammed,Ozturk,mozturk,"OU=Hospitality,OU=Employees,DC=company,DC=local","P@ssword123","Hospitality","Manager Hospitality"
|
||||||
|
|
||||||
|
Stefaan,Vrijsen,svrijsen,"OU=ICT,OU=Employees,DC=company,DC=local","P@ssword123","ICT & Security","ICT & Security Manager"
|
||||||
|
John,Ntwari,jntwari,"OU=ICT,OU=Employees,DC=company,DC=local","P@ssword123","ICT & Security","Helpdesk"
|
||||||
|
Frank,Ventiel,fventiel,"OU=ICT,OU=Employees,DC=company,DC=local","P@ssword123","ICT & Security","Systeembeheerder"
|
||||||
|
Sohail,Sosa,ssosa,"OU=ICT,OU=Employees,DC=company,DC=local","P@ssword123","ICT & Security","Applicatiebeheerder"
|
||||||
|
Frits,Franken,ffranken,"OU=ICT,OU=Employees,DC=company,DC=local","P@ssword123","ICT & Security","ICT Projectmanagement"
|
||||||
|
Bernhard,vandenBroek,bvandenbroek,"OU=ICT,OU=Employees,DC=company,DC=local","P@ssword123","ICT & Security","ICT Demandmanagement"
|
||||||
|
|
||||||
|
Anke,van Dalen-Schoten,avandalen,"OU=Finance,OU=Employees,DC=company,DC=local","P@ssword123","Finance & Control","Finance & Control Manager"
|
||||||
|
Reference in New Issue
Block a user