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 |
Visual Basic SET objRootDSE = GETOBJECT("LDAP://RootDSE") strExportFile = "C:\temp\MyExport.xls" strRoot = objRootDSE.GET("DefaultNamingContext") strfilter = "(&(objectCategory=Person)(objectClass=User))" strAttributes = "sAMAccountName,userPrincipalName,givenName,sn," & _ "initials,displayName,physicalDeliveryOfficeName," & _ "telephoneNumber,mail,wWWHomePage,profilePath," & _ "scriptPath,homeDirectory,homeDrive,title,department," & _ "company,manager,homePhone,pager,mobile," & _ "facsimileTelephoneNumber,ipphone,info," & _ "streetAddress,postOfficeBox,l,st,postalCode,c" strScope = "subtree" SET cn = CREATEOBJECT("ADODB.Connection") SET cmd = CREATEOBJECT("ADODB.Command") cn.Provider = "ADsDSOObject" cn.Open "Active Directory Provider" cmd.ActiveConnection = cn cmd.Properties("Page Size") = 1000 cmd.commandtext = ";" & strFilter & ";" & _ strAttributes & ";" & strScope SET rs = cmd.EXECUTE SET objExcel = CREATEOBJECT("Excel.Application") SET objWB = objExcel.Workbooks.Add SET objSheet = objWB.Worksheets(1) FOR i = 0 To rs.Fields.Count - 1 objSheet.Cells(1, i + 1).Value = rs.Fields(i).Name objSheet.Cells(1, i + 1).Font.Bold = TRUE NEXT objSheet.Range("A2").CopyFromRecordset(rs) objWB.SaveAs(strExportFile) rs.close cn.close SET objSheet = NOTHING SET objWB = NOTHING objExcel.Quit() SET objExcel = NOTHING Wscript.echo "Script Finished..Please See " & strExportFile |