- This topic has 1 reply, 2 voices, and was last updated 1 week, 2 days ago by
January 9, 2021 at 5:08 am #284917ParticipantTopics: 1Replies: 0Points: 12Rank: Member
Hello good time
I had a question about creating a user and an organizational unit that I was very busy with and in the end I could not find the answer and I asked you for help. My question is that I have an Excel that contains the following specifications:
id, fname, lname, email, employeeid, postcode, country, mobile, displayname, username, address, department, job
I want to write a script in PowerShell that automatically creates an organizational unit in the Active Directory relative to the desired department with these specifications and automatically adds any person who belongs to that department in that organizational unit. In general, I want to give all the Excel I have in PowerShell and add both the organizational unit and the user based on this Excel, that is, I will move them softly after adding the user in the organizational units, do it automatically Can you help me in this regard? I searched your entire site and abroad, but I did not come to any conclusion Thank you
January 10, 2021 at 3:48 pm #285064ParticipantTopics: 17Replies: 1951Points: 3,988Rank: Community Hero
While you can read xls files, it would be better to have the output be a csv as it’s directly imported into Powershell with minimal code.
Import-CSV – Import the data
Group-Object – Try grouping on property department
Get-ADOrganizationalUnit – Check to see if the OU exists
New-AdOrganizationUnit – Create new OU
Move-ADObject – Move the user into the OU
Think of it step by step. Get the data in. Write a for loop to see if the department OU exists and create it if not. Add users to department OUs. Make sure when running AD command that you specify the -Server with the DC so that you are checking and creating objects on the same server and can validate by connection the console to that server. Try to get some code built and check back here with questions.
- You must be logged in to reply to this topic.