Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create an OU under the System OU (Active Directory)

Status
Not open for further replies.

sn0rg

IS-IT--Management
Joined
Aug 5, 2005
Messages
95
Location
GB
I'm attempting to script the creation of an OU required for SMS. The OU must be created underneath the Top Level OU of System, but when I run the code, I receive the error "object not founf on the server" where the script attempts to bind to that OU.

The error doesn't occur when pointed at another Top Level OU I have manually created, so it appears that the System OU is special somehow.

Here's the sample code:
Code:
' Create OU
Set adsRootDSE = GetObject("LDAP://rootDSE")
strDomainDN = adsRootDSE.Get("defaultNamingContext")

strADsPath = "LDAP://OU=System," & strDomainDN
Set adsContainer = GetObject(strADsPath)

Set oOU=adsContainer.Create("organizationalUnit", "ou=System Management")
oOU.Put "Description", "SMS OU"
oOU.SetInfo

wscript.echo "Script Complete"
 
So it seems that the System OU is not an "Organisational Unit", it is actually a "Container". Does anyone know how to address the LDAP path for this container?
 
OK, cracked it in the end. Needed to create a Container, not an OU, thus the scrit is like this:

Code:
' Create OU

Set adsRootDSE = GetObject("LDAP://rootDSE")
strDomainDN = adsRootDSE.Get("defaultNamingContext")

strADsPath = "LDAP://CN=System," & strDomainDN

Set adsContainer = GetObject(strADsPath)

Set oOU=adsContainer.Create("Container", "CN=System Management")
oOU.Put "Description", "SMS OU"
oOU.SetInfo

wscript.echo "Script Complete"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top