Ce script exporte dans un document EXCEL l’ensemble des comptes Active Directory d’un domaine nommé domlab.com. Le contrôleur de domaine utilisé est le serveur nommé SRVPDC01
Les attributs sélectionnés dans l’export sont les suivants:
- displayName
- Name
- sn
- givenName
- distinguishedName
L’attribut userAccountControl permet de savoir si le compte est désactivé ou non. Il sert donc de condition dans le IF/THEN/ELSE
Dim ObjConnection, ObjCommand, ObjRecordSet Dim objExcel Const ADS_UF_ACCOUNTDISABLE = 2 Set ObjConnection = CreateObject("ADODB.Connection") Set ObjCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection oDomainControler = "SRVPDC01/dc=domlab,dc=com" sProperties="userAccountControl,displayName,Name,sn,givenName,distinguishedName" objCommand.Properties("Page Size") = 10000 ObjCommand.CommandText = ";(&(objectCategory=person)(objectClass=user));" & sProperties & ";subtree" ObjCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Set objExcel = WScript.CreateObject("Excel.Application") objExcel.Visible = True objExcel.Workbooks.Add objExcel.ActiveSheet.Name = "Users" objExcel.ActiveSheet.Range("A1").Activate objExcel.ActiveCell.Value = "DisplayName" objExcel.ActiveCell.Offset(0,1).Value = "Login" objExcel.ActiveCell.Offset(0,2).Value = "Nom" objExcel.ActiveCell.Offset(0,3).Value = "Prénom" objExcel.ActiveCell.Offset(0,4).Value = "Emplacement de l'objet" objExcel.ActiveCell.Offset(1,0).Activate Set ObjRecordSet = ObjCommand.Execute Do until objRecordSet.EOF intUAC=objRecordset.Fields("userAccountControl") If intUAC AND ADS_UF_ACCOUNTDISABLE Then objExcel.ActiveCell.Value = objRecordSet.fields("displayName") objExcel.ActiveCell.Offset(0,1).Value = objRecordSet.fields("Name") objExcel.ActiveCell.Offset(0,2).Value = objRecordSet.fields("sn") objExcel.ActiveCell.Offset(0,3).Value = objRecordSet.fields("givenName") objExcel.ActiveCell.Offset(0,4).Value = objRecordSet.fields("distinguishedName") objExcel.ActiveCell.Offset(1,0).Activate objRecordSet.MoveNext Else objRecordSet.MoveNext End If Loop ObjConnection.Close Set ObjConnection = Nothing Set ObjCommand = Nothing Set ObjRecordSet = Nothing objExcel.Range("A1:E1").Select objExcel.Selection.Interior.ColorIndex = 19 objExcel.Selection.Font.ColorIndex = 9 objExcel.Selection.Font.Bold = True objExcel.Cells.EntireColumn.AutoFit wscript.echo "Terminé"Ce code est correctement formaté. Vous pouvez directement le COPIER / COLLER dans un fichier VBS.
Devez-vous vraiment installer un VPN sur votre ordinateur ou votre smartphone?
Si vous téléchargez des films illégalement, si vous voulez surfer sur Internet de façon anonyme sans que le gouvernement, votre FAI ou votre employeur soit au courant ... OUI installer un VPN est définitivement une bonne idée.
Installer un VPN consiste à chiffrer toutes vos communications vers Internet. Ce n'est plus votre ordinateur qui est exposé sur Internet mais votre fournisseur de VPN.