1. Create a CSV file in Excel with the following columns: -
a. FirstName
b. LastName
c. SamAccountName
d. Description
e. Password
f. Department
2. Save the CSV file as test.csv
3. Run the following powershell command after changing the bold statement in your AD server: -
Import-Csv C:\test.csv | foreach-object {
$userprinicpalname = $_.SamAccountName +
"@domain"
$name = $_.FirstName + " " + $_.LastName
New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName
$userprinicpalname -DisplayName $name -Name $name -GivenName $_.FirstName
-SurName $_.LastName -Path "OU=Users,OU=UK,DC=domain" -AccountPassword
(ConvertTo-SecureString $_.Password -AsPlainText -force) -Enabled $True
-Department $_.Department -Description $_.Description -Manager $_.Manager
-PasswordNeverExpires $True -ChangePasswordAtLogon $False -PassThru
Add-ADPrincipalGroupMembership -identity $_.SamAccountName
-memberof "member1","member2","member3"}
No comments:
Post a Comment