Skip to content

Instantly share code, notes, and snippets.

@Arturro43
Created June 12, 2020 16:45
Show Gist options
  • Save Arturro43/e379fb201531576391d13638fdf9a31d to your computer and use it in GitHub Desktop.
Save Arturro43/e379fb201531576391d13638fdf9a31d to your computer and use it in GitHub Desktop.
add bulk users using powershell and simple csv
#importujemy moduł AD
Import-Module activedirectory
#Tu będzie importowało z csv
$ADUsers = Import-csv C:\Users\Administrator\Desktop\users.csv
#i loopujemy dla każdehgo usera
foreach ($User in $ADUsers)
{
$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$OU = $User.ou
#żeby zobazyć czy już istnieje user w AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, give a warning
Write-Warning "Konto z nazwą użytkownika $Username już istnieje w AD"
}
else
{
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName "[email protected]" ` #tutaj się edytuje domenę
-Name "$Firstname $Lastname" `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-DisplayName "$Lastname, $Firstname" `
-Path $OU `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True #uznałem, że zmiana hasła przy logowaniu będzie najlepszą opcją
}
}
#Panie Ryszardzie Stallmanie, pobłogosław mój kod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment