Comma separated files are widely used when it comes to bulk import or export of data. In this blog post I will provide a sample script to import Active Directory users from a csv file. Let’s jump in.
The CSV File
The following *.csv file serves as an example you can build on.

As you can see, the following Active Directory user account attributes are provided:
- Name
- Givenname
- E-Mail Address
- samAccountName
- ParentOU
Which commonly used settings are missing?
- Password
- User must change password at first logon
- Accounts should be enabled
The Script
In this part I will provide the script to import the users from the example csv file and fix the missing arguments we discussed above.
These are the things you have to watch out for:
- Take care of the delimiter. Omit the parameter if comma is used, because default is comma
- Watch out for the file location
- Change the AccountPassword at your choice
- add more parameters as you see fit
If you are ready, copy it into your PowerShell ISE session and have fun.
Import-Csv "C:\temp\test.csv" -Delimiter ';' |
ForEach-Object {
New-ADUser `
-Name $_.Name `
-GivenName $_.givenname `
-Surname $_.sn `
-Path $_."ParentOU" `
-SamAccountName $_.samAccountName `
-UserPrincipalName ($_.samAccountName + '@' + $env:userdnsdomain) `
-AccountPassword (ConvertTo-SecureString "123user!!!!!" -AsPlainText -Force) `
-EmailAddress $_."E-Mail Address" `
-Enabled $true `
-ChangePasswordAtLogon $true
}
A quick glance at them shows that they are enabled and ready for the first login.

Cheers!
Categories: PowerShell, Windows Server
Sehr geehrte Herr Gruenauer,
Ich barache ihre hilfe.
Ich möchte von mein freigabe im server eine bat file auf client domain mit powershell als Administrator kopieren.
Ich hatte mit befehle Copy-item gemacht , aber meine problem ist, nachdem befehle ausgefürt habe . nach den 30Sec mein datei von lauftwerk wir gelöscht.
haben sie für mich ein idee?
Mfg
Ghafouri
LikeLike
Vielen Dank für das Kommentar. Ich kann hier leider nicht helfen, Dateien werden normal nicht einfach gelöscht
LikeLike