Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript request

Status
Not open for further replies.

wowhead

IS-IT--Management
Feb 27, 2007
73
US
I'd like to have a script that scans either the network or computers listed in a file for the following information:

DNS name
Dell Service Tag
Express Service Code (optional)
Dell Model/Make (ie GX270 etc)

...and then pipe this output to a csv/txt file.

Easy enough? ;)

Any help appreciated.
 
Here is one I used to check if the battery was faulty.
You can modify it to just run on Laptops, up to you.

Code:
Dim oWMI, fso
Dim HW, HW2, instance, item, bversion
Dim  strComputer,strManufacturer,strModel,strBios,strserial
Dim BadList
Dim colBatteries, oBattery
Dim bFound, strMessage, iButtons, message
Dim bBatch
'****************************************************************************
'Run this script once to record all computers
Dim varToday, Verify, DellBattery, LastRun
Set WshShell = CreateObject("Wscript.Shell")
 
varToday = DellBattery

Verify = "HKLM\SOFTWARE\MyInstallsAndFixes\" 

 'Check if scan has run today and if so exit
On Error Resume Next
LastRun = WshShell.RegRead(Verify & "DellBattery")
If Err.Number = 0 Then
    WScript.Quit
Else
   WshShell.RegWrite Verify & "DellBattery", 0,"REG_DWORD"
End If
On Error GoTo 0 'This turns on error handling
'******************************************************************************
bBatch = True
bFound = False
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
dim quote, strArgs, i
quote=chr(34)
iButtons = 64 'vbinformation + vbOKOnly
BadList = Array("3K590","59474","6P922","C2603","C5339","C5340","C5446","C6269", _
"C6270",  "D2961","D5555","D6024","D6025","F2100","F5132","GD785","H3191","JD616", _ 
"JD617","KD494","M3006","RD857","TD349","U5867","U5882","W5915","X5308","X5329", _ 
"X5332","X5333","X5875","X5877","Y1333","Y4500","Y5466")
'On Error Resume Next

If WScript.Arguments.Count = 1 Then
strComputer = WScript.Arguments(0)
bBatch = True

If (Not IsCScript()) Then   'If not CScript, re-run with cscript...
 For i  = WScript.Arguments.Count -1 to  0 Step -1
 strArgs = WScript.Arguments(i) & Space(1) &  strArgs
Next

WshShell.Run "CScript.exe " & quote & WScript.ScriptFullName & quote & space(1) & strArgs, 1, true
   WScript.Quit             '...and stop running as WScript
End If

Else
strComputer = "."

End If 
If strcomputer = "" Then WScript.Quit
strComputer = UCase(strComputer)
'If bBatch Then 'If you got computername from command line, log results
Dim bHeader,logfile,appendout
'logfile = wshShell.ExpandEnvironmentStrings("%userprofile%") & "\desktop\DellBatteries.csv" 
logfile = "\\gtdbn1\ServerLogonLogs\DellBatteries.csv"

Const ForAppend = 8
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(logfile) then bHeader = True
Set appendout = fso.OpenTextFile(logfile, ForAppend, True)
If bHeader Then appendout.WriteLine "System,Man.,Model,BIOS,SN,Bat. DevID,Bat. Name,Message" 'Header only if new file
'End If 
Set oWMI = GetObject("winmgmts://"& strComputer)
If Err <> 0 Then
iButtons = 16
echoandlog ",,,,,,Failed:" & Err.Description 
WScript.Quit
End If
'HWInfo
Set HW = oWMI.ExecQuery("select Manufacturer,Model from Win32_ComputerSystem")
For each instance in HW
strManufacturer = trim(Instance.Manufacturer)
strModel = trim(Instance.Model)
strComputer = instance.name
Next
Set HW2 = oWMI.ExecQuery("select name,Version,SerialNumber from Win32_BIOS")
For each item in HW2 'not all manufacturers make this info available
if item.name = "Default System BIOS" then 
 Bversion = trim(item.Version)
else
 Bversion = item.name & " " & trim(item.Version)
End If

 strBios = bversion
 strSerial = trim(Item.SerialNumber)
Next

message = strManufacturer & ","  & strModel & "," & _
strBios & ","  & strserial 
Set colBatteries = oWMI.ExecQuery("SELECT deviceid, Name FROM Win32_Battery", ,48)

For Each oBattery In colBatteries
  check oBattery.Name, oBattery.DeviceID
Next
If Not bFound Then strMessage =  ",,No battery found"
If iButtons = 64 and bFound Then strMessage = strMessage & "Battery okay"
message = message & "," & strMessage 
echoandlog message
Set oWMI = Nothing
Set fso = Nothing
Set WshShell = Nothing
' Functions and subs 
Sub Check(strName, strID)
Dim i
bFound = True
strMessage =  strID & "," & strName & ","

For i = 0 To UBound(Badlist)
If instr(ucase(strName),badlist(i)) > 0  Then 
 iButtons = 16
 strMessage = strMessage & "This battery needs to be replaced!"  
End If 
Next
End Sub 

Sub EchoAndLog (message)
Dim tArray
If bBatch = true Then
'Echo output and write to Log
message = strComputer & "," & message 
'Wscript.Echo message
AppendOut.WriteLine message
Else
tArray = Split(message,",")
message = "Man.:" & vbTab & tArray(0) & VbCrLf & _
"Model:" & vbTab & tArray(1) & VbCrLf & _
"BIOS:" & vbTab & tArray(2) & VbCrLf & _
"SN:" & vbTab & tArray(3) & VbCrLf 

If UBound(tarray) >= 4 Then  
 message = message & "DevID:" & vbTab & tArray(4) & VbCrLf
End If 

If UBound(tarray) >= 5 Then  
 message = message & "Name:" & vbTab & tArray(5) & VbCrLf 
End If 

If UBound(tarray) >= 6 Then    
 message = message & "Message:" & vbTab & tArray(6)
End If 

MsgBox message, iButtons,strcomputer
End If 
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top