This Script queries LDAP provider (with WMI) for Computer names in a defined domain
Option Explicit
On Error Resume Next
'*************************************************************************
'Reading Serial Numbers from Workstations
' (c) Walter Curtis - www.sneekco.de - Have fun! Because "IT" is!
'*************************************************************************
'Demonstration Script that reads the serial number as reported by Bios
'There is no limit to the number of items that may be included.
' (c) Script by Walter Curtis
'*************************************************************************
'*************************************************************************
' Script Name BiosSerialRead.vbs
' Script Version 1.0
' Script Date: 18.05.04
' Script Created by WC
'*************************************************************************
'*************************************************************************
'Object Creation
'*************************************************************************
Dim ObjExplorer, ie, objConnection,objCommand, objRecordSet, objPing, objStatus, objXL
Dim colBIOS, objBIOS, objDocument, objWMIService
Dim ComputerName, strComputer, SerialNumber, x
' '-------------------------------------------------------------------------
' ' Creating an Internet Explorer Window to Display Information and provide Error Detection
' '-------------------------------------------------------------------------
' Set objExplorer = CreateObject("InternetExplorer.Application")
' Set ie = wscript.createobject("internetexplorer.application","event_")
' ie.navigate("javascript:'<title>Postinstallation-Process running...</title><body scroll=no></body>'")
' ie.width = 750
' ie.height = 600
' ie.toolbar = False
' ie.statusbar = False
' ie.visible = True
' Wscript.Sleep 2000
' Do
' loop while ie.readystate<>4
'-------------------------------------------------------------------------
' Creating Excel Tabelle to Display Information
'-------------------------------------------------------------------------
Set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = True
objXL.WorkBooks.Add
objXL.Cells(1, 1).Value = "Workstation Name"
objXL.Cells(1, 2).Value = "Serial Number"
objXL.Cells(1, 3).Value = "Status"
objXL.Rows("1:1").Select
objXL.Selection.Font.Bold = True
'*************************************************************************
'Get Computer Names from Active Directory
'*************************************************************************
Const ADS_SCOPE_SUBTREE = 2
x=1
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"SELECT Name, Location FROM 'LDAP://OU=Computers, OU=OTN, DC=HQ, DC=CORP' " _
& "WHERE objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
ComputerName = objRecordSet.Fields("Name").Value
'*************************************************************************
' Ping Computer before WMI Connection - Error Handling - Query Bios
'*************************************************************************
strComputer = ComputerName
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& strComputer & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
'------------------------------
'Function to use for Negative IE Display
'FailedDisplay
'------------------------------
'Function to use for Negative Excel Entry
WriteExcelFailed
'------------------------------
Else
'-------------------------------------------------------------------------
'Query PC Name for Serial Number
'-------------------------------------------------------------------------
strComputer = ComputerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
("SELECT * FROM Win32_BIOS")
For Each objBIOS in colBIOS
SerialNumber = objBIOS.SerialNumber
'------------------------------
'Function to use for Positive IE Display
' PassedDisplay
'------------------------------
'Function to use for Positive Excel Entry
WriteExcelPassed
'------------------------------
Next
End If
Next
'-------------------------------------------------------------------------
'Restarts Process until all of AD is read (defined OU only.)
'-------------------------------------------------------------------------
objRecordSet.MoveNext
x = x+1
Loop
'------------------------------
' Closes Excel File when Process is Finished
objXL.Save "C:\Temp\BiosRead.xls"
objXL.application.quit
Set obj.XL = nothing
'*************************************************************************
'End of Module
'*************************************************************************
'*************************************************************************
' Functions / Subs
'*************************************************************************
'*************************************************************************
' Function for Writing information to a html display window.
'*************************************************************************
' Sub FailedDisplay
' Set objDocument = ie.Document
' objDocument.Writeln "<html><head><title>Post Installation</title></head>"
' objDocument.Writeln "<body bgcolor='yellow'>"
' objDocument.Writeln "<br>Workstation Information Retrieved.<br>"
' objDocument.Writeln "</body></html>"
' objDocument.Writeln "<td width='50%'>" & strComputer & " = PC NOT FOUND", "</td><BR>"
' End sub
'*************************************************************************
' sub PassedDisplay
' Set objDocument = ie.Document
' objDocument.Writeln "<html><head><title>Post Installation</title></head>"
' objDocument.Writeln "<body bgcolor='yellow'>"
' objDocument.Writeln "<br>Workstation Information Retrieved.<br>"
' objDocument.Writeln "</body></html>"
' objDocument.Writeln "<td width='50%'>" & strComputer & " = " & SerialNumber, "</td><BR>"
' End sub
'*************************************************************************
'*************************************************************************
' Function WriteExcel (Passed or Failed) for Writing information to an Excel File
'*************************************************************************
sub WriteExcelPassed
objXL.Cells(x+1, 1).Value = strComputer
objXL.Cells(x+1, 2).Value = SerialNumber
objXL.Cells(x+1, 3).Value = " "
End Sub
sub WriteExcelFailed
objXL.Cells(x+1, 1).Value = strComputer
objXL.Cells(x+1, 2).Value = " "
objXL.Cells(x+1, 3).Value = "PC Not Found"
End Sub
'------------------------------
'End of Functions and Subs
'*************************************************************************
'END OF SCRIPT Checked and approved 18.05.04 - WC
'*************************************************************************