This topic contains 4 replies, has 4 voices, and was last updated by
November 10, 2017 at 11:37 pm #83954ParticipantPoints: -16Rank: 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.
November 11, 2017 at 10:50 am #83969ParticipantPoints: 0Rank: 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
November 13, 2017 at 3:35 pm #84157ParticipantPoints: -16Rank: 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.
November 13, 2017 at 3:45 pm #84160ParticipantPoints: 642Rank: Major Contributor
You could determine your OU structure with Get-ADOrganizationalUnit and re-create that structure in your new domain before you import all users.
November 13, 2017 at 4:56 pm #84175ParticipantPoints: 2Rank: 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.