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
|
Private Function AD_UserDN(sROOT_LDAP,samAccountName)
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Dim oConnection : Set oConnection = CreateObject("ADODB.Connection")
Dim oCommand : Set oCommand = CreateObject("ADODB.Command")
Dim sDN
Dim bGotResult : bGotResult = False
oConnection.Provider = ("ADsDSOObject")
oConnection.Open "Active Directory Provider"
oCommand.ActiveConnection = oConnection
oCommand.Properties("Page Size") = 1000
oCommand.Properties("Timeout") = 30
oCommand.Properties("Cache Results") = False
oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
oCommand.CommandText = _
"SELECT distinguishedName FROM 'LDAP://" & sROOT_LDAP & "'" _
& " WHERE objectClass='user' AND samAccountName = '" & samAccountName & "'"
Dim oRecordSet : Set oRecordSet = oCommand.Execute
oRecordSet.MoveFirst
Do Until oRecordSet.EOF
sDN = oRecordSet.Fields("distinguishedName").value
bGotResult = True
oRecordSet.MoveNext
Loop
oRecordSet.Close
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
If bGotResult Then
AD_UserDN = sDN
Else
AD_UserDN = "Utilisateur inconnu"
End If
On Error Goto 0
End Function
Private function PutSomeADParameters(UserDN, User, UID, GID, Home, Environnement)
Dim objUser
Set objUser = GetObject _
("LDAP://" & UserDN)
objUser.Put "msSFU30NisDomain", "Ton_Domaine_NIS"
objUser.Put "uidNumber", UID
objUser.Put "loginShell", Environnement
objUser.Put "unixHomeDirectory", Home
objUser.Put "gidNumber", GID
On Error Resume Next
objUser.SetInfo
If err.number <> 0 then
Wscript.echo User & " : ECHEC > Erreur : Champ incorrecte - " & err.number & " " & err.description
PutSomeADParameters = User & ";ECHEC > Erreur : Champ incorrecte - " & err.number & " " & err.description & vbCrLf
Else
Wscript.echo User & " : Succès"
PutSomeADParameters = User & ";SUCCES" & vbCrLf
End if
End function
Private function writeFile(text,file)
Dim fso, w
Set fso = CreateObject("Scripting.FileSystemObject")
Set w = fso.OpenTextFile(file, 8,true)
w.write(text)
w.Close
end function
Dim fso
Dim fCsv
Dim tb
Dim result
Const ForReading = 1
Const DeleteReadOnly = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
objFSO.DeleteFile("log_Export_NIS_AD.log"), DeleteReadOnly
On Error Goto 0
Set fso = CreateObject("scripting.filesystemobject")
Set fCsv = fso.OpenTextFile("audit_NIS-AD.csv", ForReading)
If Not fCsv.AtEndOfStream Then fCsv.ReadLine ' lecture ligne d'entête
While Not fCsv.AtEndOfStream
tb = Split(fCsv.ReadLine, ";")
If UBound(tb) = 12 Then
If tb(12) = 1 Then
'Wscript.echo "User : " & tb(0) & " UID :" & tb(2) & " GID:" & tb(3) & " Home:" & tb(5) & " Environnement:" & tb(6) & " A migrer:" & tb(12)
'Option Explicit
Dim UserDistinguishedName : UserDistinguishedName = AD_UserDN("Ton_Domaine_AD",tb(0))
If UserDistinguishedName = "Utilisateur inconnu" Then
Wscript.echo tb(0) & " : Echec > Utilisateur inconnu"
writeFile tb(0) & ";Echec > Utilisateur inconnu" & vbCrLf,"log_Export_NIS_AD.log"
Else
writeFile PutSomeADParameters (UserDistinguishedName,tb(0),tb(2),tb(3),tb(5),tb(6)), "log_Export_NIS_AD.log"
End If
End If
End If
Wend
Wscript.echo
Wscript.echo "Terminé !" |
Partager