how to set up folders(ou) in AD

Eliya Ben Dahan 0 Reputation points
2024-09-21T14:23:05.75+00:00

**Sorry for bad English. I am trying to define different folders for each organizational unit on the virtual server through powershell.And what I get is piles of users inside the same user folder. Attached is an example picture of the problem 1000048275

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,578 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 24,630 Reputation points MVP
    2024-09-21T14:46:22.7+00:00

    When creating users in a specific OU using PowerShell, you need to ensure that the -Path parameter in the New-ADUser cmdlet specifies the correct distinguished name (DN) of the target OU. Below is a sample script to create a user in the "Sydney Users" OU under the "Sydney" OU.

    # Define the Distinguished Name (DN) of the parent and child OUs
    $parentOU = "OU=Sydney,DC=yourdomain,DC=com"
    $childOU = "OU=Sydney Users,$parentOU"
    # Example user details
    $userFirstName = "John"
    $userLastName = "Doe"
    $userSamAccountName = "jdoe"
    $userPassword = ConvertTo-SecureString "P@ssword123" -AsPlainText -Force
    # Create a new user in the "Sydney Users" OU
    New-ADUser `
        -GivenName $userFirstName `
        -Surname $userLastName `
        -SamAccountName $userSamAccountName `
        -UserPrincipalName "$userSamAccountName@yourdomain.com" `
        -Path $childOU `
        -AccountPassword $userPassword `
        -Enabled $true `
        -PasswordNeverExpires $false `
        -ChangePasswordAtLogon $true
    
    

    Explanation:

    1. $parentOU: Specifies the distinguished name (DN) of the parent OU ("Sydney").
    2. $childOU: Specifies the distinguished name (DN) of the child OU ("Sydney Users"), which is a sub-OU under the "Sydney" OU.
    3. New-ADUser: Creates the user in the specified OU (-Path $childOU).

    Important Notes:

    • Replace DC=yourdomain,DC=com with the actual domain components of your environment.
    • Make sure the "Sydney" and "Sydney Users" OUs exist in Active Directory before running the script.
    • If the user is still being created in the default Users container, verify that the -Path parameter is correctly set and that there are no typos in the DN.

    This script will create the user "John Doe" in the "Sydney Users" OU. Adjust the details as needed to match your specific requirements.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.