How to create multiple accounts with powershell script

when you’re creating user accounts with active directory(GUI), you have to right click so many times and its time consuming.but with this script you can easily create multiple accounts continuously.This is also possible with importing scv also but if its only 10 or 20 accounts its easier to use this PowerShell script.This PowerShell can be run with the server or desktop(Windows 7) which has install rsat(Remote server administration tool) or domain controller(Windows 2008 R2)

1.Open the Active Directory PowerShell module from administrative tools

1

Here the script is locate in desktop.therefore from PowerShell navigate the script location.

2

type the script name and press enter

3

Now enter the first name of the user

4

Enter the last name of the user and enter the login name(Normally this should be first name.last or first name and first letter of the last name)

5

6

Enter the password for the user (This should comply your password policy).And if you want to add more accounts press “y”

 

7

8

This is the script.copy the script content to notepad and save as scriptname.ps1

 

 

Function CreateAdUSer
    {
        $name
        $surname
        $Sam
        $password
        $continue
            do {
                    $fname=Read-Host "Enter The First Name"
                    $sname=Read-Host "Enter the Surname"
                    $Sam=Read-Host "Enter Login Name"
                    $upassword=(Read-Host -AsSecureString "Enter the password")
                    $continue=(Read-Host "Create another user account press y")
                       New-AdUser -DisplayName $fname" "$sname -name $fname -GivenName $fname -surname $sname -SamAccountname $sam -AccountPassword $upassword -UserPrincipalName $sam -Enabled $True
                      
                }
            while ($continue -eq "y")
       
    }
    CreateAdUSer

Advertisements