Tuesday, September 09, 2008

VBS script to collect user names and service tag

Here is a script I put together that will prompt for a computer name or IP address and if it's connected, it will provide you the serial number (Dell's service tag) and the list of users who have logged onto that computer.

Save as plain text .vbs

DIM strComputer
strComputer = UserInput( "Please computer name OR IP address" )
Function UserInput( myPrompt )
UserInput = InputBox( myPrompt )
End Function

'ping host
IF Ping(strComputer) = False then
Wscript.Echo "Computer " & strComputer & " does not appear to be on the network at this time. Script will quit."
end IF

Function Ping(strHost)

dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")

for each objRetStatus in objPing
IF IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
'WScript.Echo "Status code is " & objRetStatus.StatusCode
Ping = True
WScript.Echo "IP: " & objRetStatus.ProtocolAddress
end IF
End Function

'access the WMI service on the remote machine
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'return the BIOS serial number (aka service tag)
Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For each objBIOS in colBIOS
Wscript.Echo "Serial Number: " & objBIOS.SerialNumber

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkLoginProfile")

For Each objItem in colItems
IF Len("Name: ") > 1 AND Left(objItem.Name, 5) = "WVUS\" Then
' Wscript.Echo "Full Name: " & objItem.FullName
Wscript.Echo "Name: " & objItem.Name
End if


Thijs said...

Very nice! works like a charm!

Anonymous said...

awesome thx (final a way to collect some missing serials without lifting my ass :p)

Brian Graham said...

Excellent! Glad to hear it helped.


Get the latest 'geek' post via RSS...

Subscribe below for email updates...

Enter your email address:

Delivered by FeedBurner

/* Extra Links ----------------------------------------------- */