none
How to create a new organizational unit using powershell

    Question

  • Hi, Guys

    I hope to create OU in active directory using powershell script, so I find a command "dsadd ou" in TechNet.

    http://technet.microsoft.com/en-us/library/cc770883(v=ws.10).aspx

    However, I cannot understand the example in this post.

    Now I have a server full named "hb-322.hb322dom.inetest.mycompany.com" and it in domain "hb322dom.inetest.mycompany.com".

    How could I input parameters to create OU successfully?

    Regards,

    Kaneabell

    Tuesday, April 17, 2012 11:06 AM

Answers

  • No , it would be

    dsadd ou "OU=myOU,DC=hb322dom,DC=inetest,DC=mycompany,DC=com"

    No need to add your server name because it is not part of the LDAP path.  Also, each piece of the domain name has a DC= before it.

    ZHANG,

    I would move this thread if I had the ability, but don't :)

    Wednesday, April 18, 2012 1:07 PM

All replies

  • You can use dsadd as below:

    dsadd ou "OU=SomeNewOU,DC=fabrikam,DC=com"

    Or you can use PowerShell V1:

    $Conection = [adsi] "LDAP://DC=FABRIKAM,DC=COM"
    $OU = $Connection.Create("OrganizationalUnit", "OU=SomeNewOU")
    $OU.SetInfo()

    Or a bit neater with the Quest ActiveRoles AD Cmdlets (They can be obtained here http://www.quest.com/powershell/activeroles-server.aspx)

    new-qadObject -ParentContainer 'DC=Fabrikam,DC=com' -type 'organizationalUnit' -NamingProperty 'ou' -name 'SomeNewOU'

    In all examples, the baseDN is the root of the AD tree. You can change the subpath by adding the extra levels, i.e. OU=SubOU,DC=Fabrikam,DC=com

    Tuesday, April 17, 2012 12:41 PM
  • So I should use dsadd ou command like this?

    dsadd ou "OU=myOU,DC=hb-322.hb322dom.inetest.mycompany,DC=com"

    Could you give some detail? Thanks.

    Wednesday, April 18, 2012 2:03 AM
  • Hi Kaneabell,


    Please post in PowerShell sub-forum.

    Windows PowerShell
    http://social.technet.microsoft.com/Forums/en-us/winserverpowershell/threads


    Thanks
    Zhang

    Wednesday, April 18, 2012 7:18 AM
  • No , it would be

    dsadd ou "OU=myOU,DC=hb322dom,DC=inetest,DC=mycompany,DC=com"

    No need to add your server name because it is not part of the LDAP path.  Also, each piece of the domain name has a DC= before it.

    ZHANG,

    I would move this thread if I had the ability, but don't :)

    Wednesday, April 18, 2012 1:07 PM
  • I know this is an old post, but it's 2014 now, and I would think there would be some powershell commandlets to directly modify, create and delete AD Sites and Site links like:

    Get-ADSite, Get-ADSiteLink, etc...


    • Edited by Troy12n Wednesday, May 21, 2014 2:31 PM
    Wednesday, May 21, 2014 2:28 PM