Reputation: 1
I was wondering if someone could help me Importing users from a CSV or Excel file to AD based on a Templateuser. However i have no idea how to get the SamAccountNAme and Display name row for row from a CSV file so i don't have to manually change it.
$UserInstance = Get-ADuser -Identity "SaraDavis"
New-ADUser -SAMAccountName "EllenAdams" -Instance $userInstance -DisplayName "EllenAdams"
Upvotes: 0
Views: 832
Reputation:
The CSV file would look something like this. Let's assume this information goes into c:\test\users.csv
.
SamAccountName,DisplayName
trevor,Trevor Sullivan
nancy,Nancy Drew
billy,Billy Bob
The, script would look something like this:
# 1. Get a reference to the template user, with all properties
$TemplateUser = Get-ADUser -Identity TemplateUser -Properties *;
# 2. Import the CSV file
$Data = Import-Csv -Path c:\test\users.csv;
# 3. Create a new user for each row / item in the CSV file
foreach ($Item in $Data) {
New-ADUser -Identity $Item.SamAccountName -DisplayName $Item.DisplayName -Parameter1 $TemplateUser.Property1 ... ... ... ...;
}
Upvotes: 1