IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Recuperer la liste des "physicalDeliveryOfficeName" dans l'active directory


Sujet :

VB.NET

  1. #1
    Membre actif Avatar de DeWaRs
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Décembre 2006
    Messages
    291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 291
    Points : 269
    Points
    269
    Par défaut Recuperer la liste des "physicalDeliveryOfficeName" dans l'active directory
    Bonjour a tous,

    Je cherche désespérément à récuperer la liste des tous les "physicalDeliveryOfficeName" dans l'active directory de la société pour laquelle je travail, mais en vain. J'essaie avec le code suivant mais "results " contient toujours 0 résultat.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    Dim LDAP As New DirectoryEntry("LDAP://maldap")
                Dim searcher As DirectorySearcher = New DirectorySearcher(LDAP)
                searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName")
     
                searcher.Filter = "(objectClass=physicalDeliveryOfficeName)"
     
                Dim results As System.DirectoryServices.SearchResultCollection
     
                Try
                    results = searcher.FindAll()
                Catch ex As Exception
                    Exit Sub
                End Try
     
                Dim result As System.DirectoryServices.SearchResult
     
                For Each result In results
                    '   MsgBox(Trim(CStr(result.Properties("physicalDeliveryOfficeName")
     
                Next
    Quelqu'un pourrait-il m'éclairer ?

    Cordialement.

    DeWaRs

  2. #2
    Membre éprouvé

    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Israël

    Informations forums :
    Inscription : Mars 2012
    Messages : 691
    Points : 929
    Points
    929

  3. #3
    Membre actif Avatar de DeWaRs
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Décembre 2006
    Messages
    291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 291
    Points : 269
    Points
    269
    Par défaut
    Hello,

    Voila une fonction qui marche.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
     
    Public Shared Function GetUserInfobyDomain(ByVal inSAM As String, ByVal inType As String) As String
            Using HostingEnvironment.Impersonate()
     
                Try
     
                    Dim LDAP As DirectoryEntry
                        LDAP = New DirectoryEntry("LDAP://MyDomain/CN=Users,DC=My,DC=Domain", "Domain\User", "Password")
     
     
                    Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
     
                    LDAP.AuthenticationType = AuthenticationTypes.ServerBind
                    Dim mySearcher As New DirectorySearcher(LDAP)
                    Dim mySearchResultColl As SearchResultCollection
                    Dim mySearchResult As SearchResult
                    Dim myResultPropColl As ResultPropertyCollection
                    Dim myResultPropValueColl As ResultPropertyValueCollection
                    'Build LDAP query
                    mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" & SamAccount & "))")
                    mySearchResultColl = mySearcher.FindAll()
                    'I expect only one user from search result
                    Select Case mySearchResultColl.Count
                        Case 0
                            Return "Null"
                            Exit Function
                        Case Is > 1
                            Return "Null"
                            Exit Function
                    End Select
     
                    'Get the search result from the collection
                    mySearchResult = mySearchResultColl.Item(0)
     
                    'Get the Properites, they contain the usefull info
                    myResultPropColl = mySearchResult.Properties
     
                    'displayname, mail
                    'Retrieve from the properties collection the display name and email of the user
                    myResultPropValueColl = myResultPropColl.Item(inType)
                    Return CStr(myResultPropValueColl.Item(0))
     
                Catch ex As System.Exception
                    Return "" 'ex.ToString
                    'do some error return here.
                End Try
    End function
    Pour ma question, cela donne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    GetUserInfobyDomain("NomDuUser", "physicalDeliveryOfficeName")

    En espérant que cela aide quelqu'un un jour...

    Cordialement

    DeWaRs

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 13/09/2006, 11h50
  2. Réponses: 9
    Dernier message: 27/10/2005, 22h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo