Feedback

OU´s aus Active Directory auslesen

Sprache: VB

Es kommt vor, das man gerne die OU Container im Active Directory angezeigt bekommen möchte. :-) [code]Imports System.DirectoryServices Sub GetOU() Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE") Dim dom = objRootDSE.Properties("DefaultNamingContext").Value.ToString() Dim ds As DirectorySearcher = New DirectorySearcher("LDAP://" & dom) ds.SearchScope = DirectoryServices.SearchScope.OneLevel ds.Filter = "(OU=*)" Dim dirSearchResults As SearchResult For Each dirSearchResults In ds.FindAll() console.writeline(dirSearchResults.GetDirectoryEntry().Path.ToString) Next End Sub[/code]
Imports System.DirectoryServices
Sub GetOU()
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
        Dim dom = objRootDSE.Properties("DefaultNamingContext").Value.ToString()
        Dim ds As DirectorySearcher = New DirectorySearcher("LDAP://" & dom)
        ds.SearchScope = DirectoryServices.SearchScope.OneLevel
        
        ds.Filter = "(OU=*)"
        Dim dirSearchResults As SearchResult
        For Each dirSearchResults In ds.FindAll()
            console.writeline(dirSearchResults.GetDirectoryEntry().Path.ToString)
        Next

    End Sub
Imports System.DirectoryServices
Sub GetOU()
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
        Dim dom = objRootDSE.Properties("DefaultNamingContext").Value.ToString()
        Dim ds As DirectorySearcher = New DirectorySearcher("LDAP://" & dom)
        ds.SearchScope = DirectoryServices.SearchScope.OneLevel
        
        ds.Filter = "(OU=*)"
        Dim dirSearchResults As SearchResult
        For Each dirSearchResults In ds.FindAll()
            console.writeline(dirSearchResults.GetDirectoryEntry().Path.ToString)
        Next

    End Sub