AD User Creation

Welcome Forums General PowerShell Q&A AD User Creation

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
1 year ago.

  • Author
    Posts
  • #83954

    Participant
    Points: -16
    Rank: Member

    I'm trying to re-create our domain environment on a test server by using DSC to create the environment. However, once I've created the environment exactly like our live server, I need to add the users into AD.

    I create a csv with all of the users by using

    Get-ADuser | Export-CSV -Path C:\ADUsers.csv

    When I get this same csv file onto the server to then import them, I run this command:

    import-csv -path C:\ADUsers.csv | new-aduser

    This creates all of the users, but for some reason, it doesn't create them within their OU's. Each user is created and sent to the default "Users" OU created when Active Directory services are imported to the server.

    How can I make it so that all of the users are created and placed within their correct OU's? We have around 300 users, and I don't really have a way that I can individually type in all of their names per OU.

    Thank you!

  • #83969

    Participant
    Points: 0
    Rank: Member

    Unless you use the potentially confusing -Path parameter your new user will be created in the default container which is Users unless you've changed it. See https://technet.microsoft.com/en-us/library/ee617253.aspx

    assuming you export the distinguished name of the user you'll be able to split the OU out of the distinguished name and use it with the -Path parameter to create your user in the correct OU.

    You'll need to ensure that the OUs are all created before you start creating users

    • #84157

      Participant
      Points: -16
      Rank: Member

      So, in other words, the only way to create them within the proper OU is by picking apart the distinguished name of each user, pulling the OU trees out of that, and then adding that as the -Path parameter?

      Would there be a way to automate that that you could think of? Going through 300 users one by one is what I'm trying to avoid by using Powershell.

    • #84160

      Participant
      Points: 155
      Helping Hand
      Rank: Participant

      You could determine your OU structure with Get-ADOrganizationalUnit and re-create that structure in your new domain before you import all users.

    • #84175

      Participant
      Points: 1
      Rank: Member

      You could probably just use comparison operators or pattern matching on each objects DN value in your .csv file, to create a variable called $path, and plug that into your New-User parameter. Put your .csv through a ForEach-Object loop and create your users by stepping through the csv one at a time. As long as the target OU's exist on your new server, you will be fine.

The topic ‘AD User Creation’ is closed to new replies.