'=================================================================
'
' NAME: Get_All_Computers.vbs
' AUTHOR: Alessandro Banzer
' DATE : 16.03.2011
'
'=================================================================
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(3)
Set colSheets = objWorkbook.Sheets
' Textfile für OU Scan - Textfile muss angepasst werden
Dim arrFileLines()
i = 0
Set objFile = objFSO.OpenTextFile("ou_computer.txt", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
x = 2
oucount = 1
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Activate
objExcel.ActiveSheet.Cells(1, 1).Value = "Name"
objExcel.ActiveSheet.Cells(1, 2).Value = "Description"
objExcel.ActiveSheet.Cells(1, 3).Value = "LastLogon"
objExcel.ActiveSheet.Cells(1, 4).Value = "Operating System"
objExcel.ActiveSheet.Cells(1, 5).Value = "OS Version"
objExcel.ActiveSheet.Cells(1, 6).Value = "OS Hotfix"
objExcel.ActiveSheet.Cells(1, 7).Value = "OS Servicepack"
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_UF_PASSWORD_EXPIRED = &h800000
Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
Const CHANGE_PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}"
Set objHash = CreateObject("Scripting.Dictionary")
objHash.Add "ADS_UF_DONT_EXPIRE_PASSWD", &h10000
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"<GC://" & arrFileLines(l) & ">;(objectCategory=Computer)" & _
";userAccountControl,distinguishedName,cn;subtree"
Set objRecordSet = objCommand.Execute
Do Until objRecordset.EOF
intUserAccountControl = objRecordset.Fields("userAccountControl")
If NOT intUserAccountControl AND ADS_UF_ACCOUNTDISABLE Then
For Each Key In objHash.Keys
set objcomp = getObject ("LDAP://" & objRecordset.Fields("distinguishedName").value)
lastlogon = objcomp.LastLogin
dtmValue = objcomp.description
cnName = objcomp.cn
dnName = objRecordset.Fields("distinguishedName").value
dnnamesumcount = Len(dnname)
dnnamecount = InStr(1,dnname,"OU")
cut = dnnamesumcount - dnnamecount
dncut = Right(dnname, cut)
objExcel.ActiveSheet.Cells(x, 1).Value = cnName
objExcel.ActiveSheet.Cells(x, 2).Value = dtmValue
objExcel.ActiveSheet.Cells(x, 3).Value = lastlogon
objExcel.ActiveSheet.Cells(x, 4).Value = objcomp.operatingSystem
objExcel.ActiveSheet.Cells(x, 5).Value = objcomp.operatingSystemVersion
objExcel.ActiveSheet.Cells(x, 6).Value = objcomp.operatingSystemHotfix
objExcel.ActiveSheet.Cells(x, 7).Value = objcomp.operatingSystemServicePack
x = x + 1
Next
End If
objRecordset.MoveNext
Loop
objConnection.Close
oucount = oucount + 1
Next
Set objRange = objWorksheet.UsedRange
objRange.EntireColumn.Autofit()
objExcel.close
wscript.echo "done !"