I've currently got the code down below, however I get $null returned on the $userpass variable. I've checked the CSV file and all should be correct.
Import-Module activedirectory
#Dit deel van het script is voor het verzamelen van informatie die in de commands gestopt wordt.
$csvpad = Read-Host -Prompt 'Geef het pad naar het CSV bestand op (zonder bestandsnaam)
ZONDER backslash, bijvoorbeeld: D:\Gebruikers mappen'
$csvbestand = Read-Host -Prompt 'Geef het CSV bestandsnaam op'
#Voor het opslaan van de data uit het opgegeven .CSV bestand in de $users variable
Write-Host "CSV bestand importeren!"
$users = Import-Csv -Path "$csvpad\$csvbestand"
#Loop om door elke rij in het CSV bestand te gaan.
Foreach ($user in $users)
{
#Leest de data van elk veld in elke rij en geeft de juiste data aan de juiste variable.
$displayname = $user.Voornaam + " " + $user.Achternaam
$userfirstname = $user.Voornaam
$userlastname = $user.Achternaam
$username = $user.Gebruikersnaam
$usermail = $user.Voornaam + "." + $user.Achternaam + "@" + $user.Domein
$ou = $user.OU
$userpass = $user.Wachtwoord
#Als de user niet in AD bestaat gaat deze door met het maken van een nieuwe account.
New-ADUser -Name "$displayname" -DisplayName "$displayname" -GivenName "$userfirstname" -Surname "$userlastname" -Enabled $true -SamAccountName "$username" -EmailAddress "$usermail" -Path "$ou" -AccountPassword (ConvertTo-SecureString $userpass -AsPlainText -Force) -ChangePasswordAtLogon $true -PasswordNeverExpires $true
}
Write-Host "Users uit het CSV bestand zijn aangemaakt!"
Here is the CSV I am using (data is as random as it is just a learning project of school).
Voornaam;Achternaam;Domein;Gebruikersnaam;Wachtwoord;OU;Berekening usernames
Test;Account1;01testict.nl;Te.Account1;P@ssw0rd;OU=Users,DC=01testict,DC=nl;Te
Testing;Account2;01testict.nl;Te.Account2;P@ssw0rd;OU=Users,DC=01testict,DC=nl;Te
Test123;Account3;01testict.nl;Te.Account3;P@ssw0rd;OU=Users,DC=01testict,DC=nl;Te
Test971;Account4;01testict.nl;Te.Account4;P@ssw0rd;OU=Users,DC=01testict,DC=nl;Te
Test652;Account5;01testict.nl;Te.Account5;P@ssw0rd;OU=Users,DC=01testict,DC=nl;Te
Any ideas?
ConvertTo-SecureStringat the end of the loop you are missing a space between$userpassand the-AsPlainTextparameter.Wachtwoord? Are there any spaces in that column name?