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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically grabbing domain info

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I have the following script for creating an OU. This works as expected.

Code:
$objDomain = [ADSI]"LDAP://localhost:389/DC=MyCompany,DC=Local"

$objOU = $objDomain.Create("organizationalUnit", "ou=MarkTestOU")

$objOU.SetInfo()

If however I try to dynamically grab the domain info it fails
Code:
$RootDSE = New-Object directoryservices.directoryentry('LDAP://rootDSE') 
$Root = New-Object directoryservices.directoryentry("LDAP://$($RootDSE.DefaultNamingContext)") 

$objDomain = [ADSI]"LDAP://localhost:389/"+$Root.DistinguishedName

$objOU = $objDomain.Create("organizationalUnit", "ou=MarkTestOU")

$objOU.SetInfo()

Can anyone assist?
 
Have you tried

Code:
$objDomain = [ADSI]("LDAP://locahost:389/" + $RootDSE.DefaultNamingContext)

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
So this is the full code that worked for me

Code:
$rootDSE = New-Object DirectoryServices.DirectoryEntry("LDAP://rootDSE")
$objDomain = [ADSI]("LDAP://localhost:389/" + $rootDSE.DefaultNamingContext)
$objOU = $objDomain.Create("organizationalUnit", "ou=MyTestOU")
$objOU.SetInfo()

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top