Const strSourceFile = "computers.txt"
Const strDestFile = "output.csv"
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSourceFile = objFSO.OpenTextFile(strSourceFile, ForReading)
Set objDestFile = objFSO.CreateTextFile(strDestFile, True)
objDestFile.WriteLine """Computername"",""Service Tag"",""User Name"""
Do While Not objSourceFile.AtEndOfStream
strComputer = objSourceFile.ReadLine
If Ping(strComputer) Then
objDestFile.WriteLine """" & strComputer & """,""" & GetSerial(strComputer) & """,""" & GetUsername(strComputer) & """"
End If
Loop
objDestFile.Close
msgbox "done!"
Function GetSerial(strComputer)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")
'GetSerial = ""
For Each objSMBIOS In colSMBIOS
'GetSerial = objSMBIOS.SerialNumber
GetSerial = objSMBIOS.SerialNumber
Exit For
Next
End Function
Function GetUsername(strComputer)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select Username from Win32_ComputerSystem")
'GetSerial = ""
For Each objComputer In colComputer
GetUsername = objComputer.Username
Exit For
Next
End Function
Function Ping(strComputer)
Dim objPing, objStatus
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("SELECT Replysize FROM Win32_PingStatus WHERE address = '" & strComputer & "'")
Ping = False
For Each objStatus in objPing
If Not IsNull(objStatus.ReplySize) Then Ping = True
Next
End Function
|