Powershell: Add new user accounts in Active Directory.

You would like to create bulk Active Directory user accounts; you can modify your csv file according to the below structure and run the PowerShell script. Your user accounts will be created within the respective Organizational Unit. Notice that if you have “Fine Grained Password Policy” you might need to disable it during this process or make sure passwords you input in csv file are compatible with the policy.

<strong>create_user.ps1</strong>

$usernames = Import-Csv "c:\scripts\lists\new_users.csv"
Clear-Host
foreach($user in $usernames)
{ 
   $name = $user.samaccountname
   $parola = $user.password
   $display = $user.name
   $ou = $user.ou
   $office = $user.ou
      
   try{  
        echo "Creating new user account : $name -> $display"
        dsadd user "cn=$name,ou=$ou,dc=mycompany,dc=com,dc=tr" -samid $name -upn $name"@mycompany.com.tr" -hmdir \\mycompany\home\$name -hmdrv Z: -desc $display -acctexpires never -email      
                    $name"@mycompany.com.tr" -display $display -office $office -disabled no -mustchpwd no -pwd $parola >> log.txt              
   }catch{ 
    $_.Exception.Message
    Break       
   }Finally
     {
      "end of script"
     }        
}

new_users.csv

    1. name,ou,samaccountname,password
    1. Selda Sert,Accounting,selda.sert,bA8fs2n
    1. Stephen White,Accounting,stephen.white,vP4Kd2n
    1. Robert Dere,IT Department,robert.dere,vD2JZ3h
    1. Ahmed Selim,IT Department,ahmed.selim,dB4JT5h

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Yandex.Metrica