Bulk creation of AD user in multiple OU

Welcome Forums General PowerShell Q&A Bulk creation of AD user in multiple OU

Viewing 2 reply threads
  • Author
    • #281147
      Topics: 1
      Replies: 0
      Points: 14
      Rank: Member

      Newbie powershell learner here.

      I wanted to create a script that will automate the bulk creation of our AD

      I have an import csv with list of name,location,OU,etc. (I wanted to remove the OU property on the CSV file and have a script where it will automatically put in the user account on it’s OU by each location)

      if (! (Get-ADUser -Filter {SamAccountName -eq $Username}))      {

      Write-Warning “A user account $Username has already exist in Active Directory.”        }


      #If a user does not exist then create a new user account

      #Account will be created in the OU listed in the $OU variable in the CSV file; don’t forget to change the domain name in the”-UserPrincipalName” variable


      -SamAccountName $Username

      -UserPrincipalName “[email protected]

      -Name “$Firstname $Lastname”

      -GivenName $Firstname

      -Surname $Lastname

      -Enabled $True

      -ChangePasswordAtLogon $True

      -DisplayName “$Lastname, $Firstname”

      -Department $Department

      -Path $OU

      -Description $description

      -state $State

      -street $Street

      -office $Office

      -EmailAddress $Email

      -city $city

      -PostalCode $Zipcode

      -Country $Country

      -Title $Jobtitle

      -Company $Company ` -AccountPassword (convertto-securestring $password -AsPlainText -Force)


    • #281284
      Topics: 5
      Replies: 349
      Points: 632
      Helping Hand
      Rank: Major Contributor
    • #281573
      Topics: 17
      Replies: 1951
      Points: 3,986
      Helping Hand
      Rank: Community Hero

      How are you generating the username? There is usually name collisions like John Smith, Jane Smith, etc., so it’s a bit more involved that joining parts of a name. If you have that information from HR, you should also have the EmployeeId and should set it in AD. Eventually you will want to reconcile the data to ensure there is a match 1:1 for users, and then your script can update existing users and create new users.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.