Home » Posts tagged 'hardware details'

Tag Archives: hardware details

VB Script to collect Windows server hardware details on multiple machines.

VB Script to collect Windows server hardware details. Script will Collect Serial Number, Make, Model, OS, CPU, RAM, Drive details on multiple servers remotely.

Copy below contents and save as filename.vbs and create a machines.txt will all server names one per line.

 

***********************************************************************************************************************

Option Explicit

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Const PATH_TO_INPUT = “Machines.txt”
Const PATH_TO_OUTPUT = “MachineInventory.csv”

Dim fso
Set fso = WScript.CreateObject(“Scripting.FileSystemObject”)

Dim shl
Set shl = WScript.CreateObject(“WScript.Shell”)

Dim input
Set input = fso.OpenTextFile(PATH_TO_INPUT)

Dim output
Set output = fso.CreateTextFile(PATH_TO_OUTPUT, True)

output.WriteLine “Hostname,Serial Number,Make,Model,BIOS Version,Operating System,CPU,Memory (MB),Disk Drives”

Dim wmiService
Dim wmiResults

Dim hostname
Dim make
Dim model
Dim biosversion
Dim operatingSystem
Dim serialNumber
Dim cpu
Dim memory
Dim drives

Dim line
Dim exec
Dim pingResults
While Not input.AtEndOfStream
line = input.ReadLine
hostname = “”
make = “”
model = “”
biosversion = “”
operatingSystem = “”
serialNumber = “”
cpu = “”
memory = “”
drives = “”

Set exec = shl.Exec(“ping -n 2 -w 1000 ” & line)
pingResults = LCase(exec.StdOut.ReadAll)

If InStr(pingResults, “reply from”) Then
WScript.Echo “Reply From: ” & line
On Error Resume Next

Set wmiService = GetObject(“winmgmts:\\” & line & “\root\CIMV2”)

If Not Err.Number = 0 Then
output.WriteLine line & “,Error: ” & Err.Description
WScript.Echo line & “,Error: ” & Err.Description
On Error GoTo 0
Else
On Error GoTo 0
hostname = line

Set wmiResults = wmiService.ExecQuery(“SELECT * FROM Win32_BIOS”, “WQL”, wbemFlagReturnImmediately + wbemFlagForwardOnly)

Dim item
For Each item In wmiResults
serialNumber = Trim(item.SerialNumber)
biosversion = Trim(item.SMBIOSBIOSVersion)
Next

Set wmiResults = wmiService.ExecQuery(“SELECT * FROM Win32_ComputerSystem”, “WQL”, wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
make = Trim(item.Manufacturer)
model = Trim(item.Model)
Next

Set wmiResults = wmiService.ExecQuery(“SELECT * FROM Win32_OperatingSystem”, “WQL”, wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
operatingSystem = Trim(item.Name)
operatingSystem = Split(operatingSystem, “|”)(0)
memory = Round(Trim(item.TotalVisibleMemorySize) / 1024, 2)
Next

Set wmiResults = wmiService.ExecQuery(“SELECT * FROM Win32_Processor”, “WQL”, wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
cpu = Trim(item.Name)
Next

Set wmiResults = wmiService.ExecQuery(“SELECT * FROM Win32_LogicalDisk WHERE DriveType=3”, “WQL”, wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
drives = drives & Trim(item.DeviceID) & ” ” & Round(Trim(item.Size) / (1024^2), 2) & “;”
Next

output.WriteLine hostname & “,” & serialNumber & “,” & make & “,” & model & “,” & biosversion & “,” & operatingSystem & “,” & cpu & “,” & memory & “,” & drives
WScript.Echo hostname & “,” & serialNumber & “,” & make & “,” & model & “,” & biosversion & “,” & operatingSystem & “,” & cpu & “,” & memory & “,” & drives
End If
Else
output.WriteLine line & “,No Response”
WScript.Echo line & “,No Response”
End If
Wend

output.Close
input.Close

Set wmiService = Nothing
Set wmiresults = Nothing

***********************************************************************************************************************

 

Thanks,

WintelAdmin

 


Visitors Count

Subscriber Count

    3980
May 2017
M T W T F S S
« Apr    
1234567
891011121314
15161718192021
22232425262728
293031