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

VBScript Discussion :

VBS - vérifier existence utilisateur dans AD


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre expérimenté
    Inscrit en
    Mai 2008
    Messages
    189
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 189
    Par défaut VBS - vérifier existence utilisateur dans AD
    Bonjour,


    Je cherche à vérifier l'existence d'un utilisateur dans l'AD a partir du SamAccountName.

    j'ai trouvé le script chez microsoft mais il ne semble pas trouver les users que je lui soumets :

    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
    on error resume next
    strUserName = "prefix.usertest"
    dtStart = TimeValue(Now())
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"
     
    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection
     
    objCommand.CommandText = _
        ";(&(objectCategory=User)" & _
             "(samAccountName=" & strUserName & "));samAccountName;subtree"
     
    Set objRecordSet = objCommand.Execute
     
    If objRecordset.RecordCount = 0 Then
        WScript.Echo "sAMAccountName: " & strUserName & " does not exist."
    Else
        WScript.Echo strUserName & " exists."
    End If
    objConnection.Close
    le user does not exist a chaque essai :/, meme lorsque je lui donne un samaccoutname de l'AD.

    si qqun a une idée je prends volontier.

  2. #2
    Membre expérimenté
    Inscrit en
    Mai 2008
    Messages
    189
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 189
    Par défaut
    j'ai trouvé une autre source sur ce forum, mais j'obtiens le meme 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
    21
    22
    23
    24
    User = "toto.tata"
    if Exist_LDAP_User(User) then
    wscript.echo "l'utilisateur existe"
    else
    wscript.echo "l'utilisateur n'existe paaaaaaaaaaaas"
    End If
     
    Private Function Exist_LDAP_User(samAccountName)
        strUserName = samAccountName
        Set objConnection = CreateObject("ADODB.Connection" )
        objConnection.Open "Provider=ADsDSOObject;"
        Set objCommand = CreateObject("ADODB.Command" )
        objCommand.ActiveConnection = objConnection
        objCommand.CommandText = "<LDAP://dc=ho,dc=cma-cgm,dc=com>;(&(objectCategory=User)" & "(samAccountName=" & strUserName & " ));samAccountName;subtree"
     
        Set objRecordSet = objCommand.Execute
     
        If objRecordset.RecordCount = 0 Then
            Exist_LDAP_User = False
        Else
            Exist_LDAP_User = True
        End If
        objConnection.Close
     End Function
    y me répond : l'utilisateur n'existe paaaaaaaaaaaas

  3. #3
    Membre expérimenté
    Inscrit en
    Mai 2008
    Messages
    189
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 189
    Par défaut
    j'ai trouvé !

    par contre j'ai adapté une barre de progression, des fichiers log et erreur ca donne un truc un peu difficile a lire dsl :
    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    On Error Resume Next
    '__________________________________________
    'variables
    '__________________________________________
    FichierSource = "Source.txt"
    FichierReprise = "Reprise.txt"
    FichierError = "Error.log"
    fichierLog = "Parser.log"
    '__________________________________________
    'constantes
    '__________________________________________
    Const ForReading = 1
    Const OverWriteFiles = True
    Const ForAppending = 8
    Const ADS_PROPERTY_CLEAR = 1 
    '__________________________________________
    'parametrage
    '__________________________________________
    '__________________________________________
    'parametrage
    '__________________________________________
    ScriptPath = Left(WScript.ScriptFullName,(Len(WScript.ScriptFullName) - (Len(WScript.ScriptName) + 1)))
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objLogFile = objFSO.OpenTextFile (ScriptPath & "\" & fichierLog, ForAppending, True)
    Set objErrFile = objFSO.OpenTextFile (ScriptPath & "\" & FichierError, ForAppending, True)
    Set objReprFile = objFSO.OpenTextFile (ScriptPath & "\" & FichierReprise, ForAppending, True)
    If objFSO.FileExists(ScriptPath & "\" & Fichiersource) Then
    Set objTextFile = objFSO.OpenTextFile(ScriptPath & "\" & Fichiersource, ForReading)
    Else
        Wscript.Echo "Fichier introuvable, tâche annulée"
    	Wscript.quit
    End If
    Set objShell = CreateObject("WScript.Shell")
     
    Dim gdocProgressBar 'requis pour objet internet explorer
    Dim goieProgressBar	'requis pour objet internet explorer
    Set gdocProgressBar = Nothing
    Set goieProgressBar = Nothing
    Set objDictionary = CreateObject("Scripting.Dictionary")
     REM objDictionary.Remove("key")
     REM objDictionary.RemoveAll 
    '__________________________________________
    'decompte des iteration
    '__________________________________________
    i = 0
    Do Until objTextFile.AtEndOfStream 
        strNextLine = objTextFile.Readline
        objDictionary.Add i, strNextLine
        i = i + 1
    Loop
    	intCount = objDictionary.Count
    '__________________________________________
    'Step ProgressBar
    '__________________________________________
    	ProgressBarStep = 100 / intCount
    	ProgressBarAccounting = 0
    	'wscript.echo ProgressBarStep
     
    '-----------------------------------------------------------------
    'traitement
    '-----------------------------------------------------------------
    u = 0
    For Each objItem in objDictionary
    'Wscript.Echo objDictionary.item(u)
    'WScript.Sleep 1000
    Utilisateur = objDictionary.item(u)
    modifyAd(Utilisateur)
    ProgressBarAccounting = ProgressBarAccounting + ProgressBarStep
    ProgressBar ProgressBarAccounting 
    u=u+1
    Next
    '-----------------------------------------------------------------
    '-----------------------------------------------------------------
    '__________________________________________
    'Sortie du traitement
    '__________________________________________
    wscript.echo ("Export terminé")
    objLogFile.WriteLine("" & date & " - " & hour(time)  & "h" & minute(time)  & _ 
    	" : Export terminé")
    WScript.Sleep 1000
    ProgressBar -1
    objLogFile.close
    objErrFile.close
    objReprFile.close
    objTextFile.close
     
    '__________________________________________
    'fonction de consultation AD
    '__________________________________________
    Function modifyAd(utilisateur)
            Set objCommand = CreateObject("ADODB.Command")
            Set objConnection = CreateObject("ADODB.Connection")
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
            objCommand.ActiveConnection = objConnection
            strBase = "<LDAP://dc=ho,dc=cma-cgm,dc=com>"
            strFilter = "(&(objectClass=user)(sAMAccountName="&utilisateur&"))"
            strAttributes = "distinguishedName,ScriptPath"
            strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
            objCommand.CommandText = strQuery
            Set objRecordSet = objCommand.Execute
    		if objRecordSet.recordcount <> 0 then
    				objLogFile.WriteLine utilisateur & ";" & objRecordSet.Fields("distinguishedName") & ";" & objRecordSet.Fields("ScriptPath")
    		Else
    		objErrFile.WriteLine "utilisateur : " & utilisateur & " introuvable"
    		End If
    		objConnection.Close
    End function
    '__________________________________________
    'fonction de la progress bar
    '__________________________________________
    	Sub ProgressBar(intPercent)
    'intPercent doit rester entre 0 et 100 
    	If gdocProgressBar Is Nothing Then
    		If ((Cint(intPercent) >= 0) And (Cint(intPercent) <= 100)) Then
    			Set goieProgressBar = CreateObject("InternetExplorer.Application")
    			goieProgressBar.Offline = True
    			goieProgressBar.AddressBar = False
    			goieProgressBar.Height = 100
    			goieProgressBar.Width = 250
    			goieProgressBar.MenuBar = False
    			goieProgressBar.StatusBar = False
    			goieProgressBar.Silent = True
    			goieProgressBar.ToolBar = False
    			goieProgressBar.Navigate "about:blank"
    			Do While goieProgressBar.Busy
    				WScript.Sleep 100
    			Loop
    			'On Error Resume Next
    			Set gdocProgressBar = Nothing
    			Do Until Not gdocProgressBar Is Nothing
    				WScript.Sleep 100
    				Set gdocProgressBar = goieProgressBar.Document
    			Loop
    			gdocProgressBar.Open
    			gdocProgressBar.Write "<html><head><title>"
    			gdocProgressBar.Write "Status"
    			gdocProgressBar.Write "</title></head><body><center>"
    			gdocProgressBar.Write "<TABLE width=200 border=3 frame=box><tr><td>"
    			gdocProgressBar.Write "<TABLE id=status width=0 border=0 cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>"
    			gdocProgressBar.Write "<tr><td>&nbsp</td></tr></table></td></tr></table></center></body></html>"
    			gdocProgressBar.Close
    			goieProgressBar.Visible = True			
    		Else
    			Exit Sub
    		End If
    	End If
    	'Ferme la barre d'etat
    	If Not gdocProgressBar Is Nothing Then
    		If ((Cint(intPercent) < 0) Or (Cint(intPercent) > 100)) Then
    			goieProgressBar.Visible = False
    			Set gdocProgressBar = Nothing
    			goieProgressBar.Quit
    			Set goieProgressBar = Nothing
    			Exit Sub
    		End If
    	End If
    	'met a jour la barre d'etat
    	If Cint(intPercent) = 0 Then
    		gdocProgressBar.all.status.width = "1%"
    		gdocProgressBar.all.status.bgcolor = "#FFFFFF"
    	Else
    		gdocProgressBar.all.status.width = Cstr(Cint(intPercent)) & "%"
    		gdocProgressBar.all.status.bgcolor = "#0000FF"
    	End If
     
    End Sub
    le fichier source doit contenir les samaccountname (nom NT4), un par ligne

    ex :
    toto
    titi
    tutu
    ...

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

Discussions similaires

  1. [XL-2010] Vérifier existence occurence dans variable tableau
    Par tomo80 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 29/11/2012, 16h56
  2. Réponses: 0
    Dernier message: 05/02/2009, 13h16
  3. Vérifier l'existence d'un utilisateur dans l'Active drectory
    Par dev_gahie dans le forum Général Java
    Réponses: 3
    Dernier message: 14/04/2008, 17h36
  4. Vérifier existence fonction dans une classe
    Par zoparg dans le forum Langage
    Réponses: 2
    Dernier message: 17/02/2007, 13h29
  5. Réponses: 5
    Dernier message: 29/03/2006, 14h55

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