Вы находитесь на странице: 1из 2

AD Users from CSV using Powershell Script

1. Power shell script execution should disable before running script.


Set-ExecutionPolicy Unrestricted

2. Check module for Active Directory install in Power shell


Get-Module Listavailable

3. Create a CSV file as per below format.

4. Script Details
a. This step will import Active Directory module to create users
Import-Module ActiveDirectory
b. This step will CSV file for users. Change path and name for CSV as per
your file name and path. Second this step crates a UPN (user principal
name) using samAccountName and your domain name.
c. Change domain name as per your domain name in CSV and also in below
command.
Import-Csv "C:\Scripts\NewUsers.csv" | ForEach-Object {
$userPrincinpal = $_."samAccountName" + "@Rico.local"
d. Below step crates user using properties CSV and earlier define user
principale name format. Change OU in CSV as per your desire. Also it
crates a user with default password Pass@123 and also enable option for
change password at first logon.
New-ADUser -Name $_.Name `
-Path $_."ParentOU" `
-SamAccountName $_."samAccountName" `
-UserPrincipalName $userPrincinpal `
-AccountPassword (ConvertTo-SecureString "Pass@123" -AsPlainText
-Force) `
-ChangePasswordAtLogon $true `

-Enabled $true
e. Below command add users in Domain users in account group, you can
change group or delete this line. If you remove below line users will be
automatically member of Domain users group as default.
Add-ADGroupMember "Account" $_."samAccountName";
}
5. Now Run script in power shell as per below command or right click file and
select Run with Powershell
PS C:\Scripts> .\Create-BulkADUsers-CSV.ps1

Вам также может понравиться