Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :
TheServerGeeks

IT with everything IT

Create Bulk Active Directory Users

/

In IT world organizations will have employees leaving and joining the company. This cycle will continue forever. but, consider you are working for a School or large organization, where users join in a large number and you have to manually create the User accounts for them. Its miserable right

Let’s just take a look at the PowerShell way to automate the user creation. Run the First 2 lines to create an Excel file containing users First Name and LastName in it or get it done by one your recruitment team. then run the rest of the Cmdlets to create AD User accounts for each row in the Excel spreadsheet.

If you want to generate random/strong passwords for the users, then Follow how to generate random passwords using powershell

$FirstName=Read-Host “Enter FirstName”
$LastName=Read-Host “Enter LastName” Echo “
$FirstName,$LastName” > C:\users.csv

Use this Cmdlets to create csv file with the user FirstName and LastName properties and use this file to create user accounts

 # Comment out above lines with # and edit C:\users.csv for multiple users 

Import-Module ActiveDirectory

$csvfile =Import-Csv -Path D:\Users.Csv
foreach ($user in $csvfile) {
New-AdUser ` -AccountPassword (ConvertTo-SecureString -AsPlainText "D3faultP0ss" -Force) ` -Name $user.FirstName ` -GivenName $user.FirstName ` -Surname $user.LastName ` -Enabled $true ` -DisplayName ($User.FirstName + "," + $LastName)` -SamAccountName $user.FirstName ` -UserPrincipalName ($user.FirstName + "@" + "Contoso.com")` -ChangePasswordAtLogon $true ` -HomeDrive "H:" ` -HomeDirectory "D:\Home\$($user.FirstName)"` -Path "OU=TestUsers,DC=Contoso,DC=com" ` mkdir "D:\home\$($User.FirstName)" Icacls "D:\home\$($user.FirstName)" /Grant "$($user.FirstName):(OU)(CI)M" $User1=Get-AdUser -Identity "$($User.FirstName)" Add-AdGroupMember -identity Accounting -Member "User1"
}

Copy and paste the above codes in to .Ps1 file. This will use the csv file which is created previously and set the account password to “D3faultP0ss“.

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar