Let me give a scenario:
# generic way to determine ANY ORGANISATION LDAP PATH
$objOU=[ADSI]"LDAP://ROOTDSE"
$OBJOU.defaultNamingContext
Is there similar way like above to determine OU structure ?
Sorry, could you be more specific??
"Determine the AD OU structure" - of which OU exactly, how? :)
Martin
In company A, their OU structure could be like this:
OU Country1
OU Computers
OU Users.
In company B, their OU structure could be like this:
OU Dept1
OU Users_Computers
If i write a script for Company A, i hAve to use a regular expression to
detect Company A OU structure.
Similarly if i write a script for Company B, the regular expression used in
Company A cannot be applied to Company B. This means i have to write a
regular expression for Company B.
Is there a "generic" way to determine the OU structure of Two companies,
rather than *hard code" a regular express for Company A and Company B
respectively ?
You could of course have a logic that will match OU based on some kind of
mask (for example returning first OU that contains work Users or Computers),
however don't think such code would be too useful.
Martin
"IT STAFF" <jkk...@hotmail.com> wrote in message
news:ep7915uX...@TK2MSFTNGP02.phx.gbl...
Martin - I am definitely concerned about this question as well. You
say that you need to do the "equivalent of Get-ChildItem (which can be
done)" Yes, understood, but HOW is it done for OU structure?
jj
ah, now I understand the problem :) Having a look at
http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry_properties.aspx, I
can see that DirectoryEntry class contains property Children.
Therefore you retrieve reference to any directory entry and then you can
have a look at $DirectoryEntry.Childen. If you are interested, I can give
you code how to do that.
Martin
Excellent. Thanks, Martin. So you get the top level, see if it has
children, etc??
Yeah, if you were able to post code, that would be great.
you can try below code (don't have AD here, so I could try):
Function AD\Get-OU ([string]$Path = $([ADSI]"LDAP://
ROOTDSE").defaultNamingContext) {
$DS = New-Object DirectoryServices.DirectorySearcher($Path,
"(objectclass=organizationalUnit)", $Null,
[DirectoryServices.SearchScope]::OneLevel)
[array]$OUs = $DS.FindAll()
ForEach ($OU in $OUs) {
$OU.GetDirectoryEntry()
}
}
It should work (or require just little bit testing).