| 12
 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
 
 | On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
objCommand.CommandText = _
    "SELECT ADsPath, FROM 'LDAP://' WHERE objectCategory='group''"  
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fileLog = FSO.OpenTextFile("C:\Test\listgroups_complet.txt", 8, True)
 
'PostLog("AccountName;DisplayName;FirstName;LastName;Description;Disabled;ExpirationDate;Locked")
 
Do Until objRecordSet.EOF
     strPath = objRecordSet.Fields("ADsPath").Value
 
     Set objGroup = GetObject(strPath)
 
     objGroup.GetInfo
 
     objGroup.GetInfoEx Array("primaryGroupToken"), 0
     sPrimaryGroupToken = objGroup.primaryGroupToken
 
     wscript.echo objGroup.Name
 
'Ajout reinitialisation variable
     arrMemberOf = Null
     arrMemberOf = objGroup.GetEx("member")
     If arrMemberOf <> Null Then
      	For Each strMember in arrMemberOf
        set objUser = GetObject ("LDAP://" & strMember)
	sClass = objUser.Class
	sSAMAccountName = objUser.sAMAccountName
	sDescription = objUser.Description
	sDisplayName = objUser.DisplayName
	dtmAccountExpiration = objUser.AccountExpirationDate 
	strExpirationDate = ""
	If Err.Number = -2147467259 Or dtmAccountExpiration = "01/01/1970" or dtmAccountExpiration = "01/01/1601 02:00:00" or dtmAccountExpiration = "01/01/1601 01:00:00" Then
	     strExpirationDate = "None"
	Else
	     strExpirationDate = objUser.AccountExpirationDate
	End If
	strAccountDisabled = ""
	strAccountDisabled = objUser.AccountDisabled
'	wscript.echo strMember
	sDomain = Right(strMember,Len(StrMember)-InStr(strMember,"DC=")-2)
'	wscript.echo sDomain
	sDomain = Left(sDomain, InStr(sDomain,",")-1)
'	wscript.echo sDomain
	fileLog.WriteLine objGroup.Name & ";" & sPrimaryGroupToken & ";" & sDomain & ";" & sClass & ";" & sSAMAccountName & ";" & sDescription & ";" & sDisplayName & ";" & strExpirationDate & ";" & strAccountDisabled & ";" & strMember
        Next
    End If
    objRecordSet.MoveNext
Loop
 
fileLog.Close
 
Set fileLog = FSO.OpenTextFile("C:\Test\listgroups_complet.flag", 8, True)
fileLog.WriteLine "fin"
FileLog.Close
 
Wscript.quit
 
'=============================================================================================================
Sub PostLog(sItem)
'=============================================================================================================
'   ***********
'   * Fichier LOG
'   ***********
On Error Resume Next
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fileLog = FSO.OpenTextFile("C:\Test\listusers.txt", 8, True)
fileLog.WriteLine sItem
fileLog.Close
Err.Clear
End Sub
 
'=============================================================================================================
Sub Listmembers(sItem, sGroupName)
'=============================================================================================================
'wscript.echo sItem
Set objGroup = GetObject ("LDAP://" & sItem)
objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
 
For Each strMember in arrMemberOf
    set objUser = GetObject ("LDAP://" & strMember)
    sItem = sGroupName & ";" & objUser.sAMAccountName
    fileLog.WriteLine sItem
Next
End Sub | 
Partager