Created
June 25, 2015 18:16
-
-
Save Ashex/3bd3816987dc4736828e to your computer and use it in GitHub Desktop.
Get hardware details of windows machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' ----------------------------------------------------------------- | |
' Syntax: cscript collectsysteminfo.vbs file | |
' Author: Ahmed Osman | |
' Date: September 14, 2011 | |
' Description: | |
' Supply the script with a list of DNS machine names and it will retrieve basic system details | |
'------------------------------------------------------------------ | |
Option Explicit | |
On Error Resume Next | |
Dim oLogObject, oMsgOutput, oLogOutput, sLogFile, sMsgFile | |
set oLogOutput = nothing | |
Dim aArgs, strComputer, objWMIService, colItems, objItem, strMsg, logMsg | |
Dim arrComputers, item, strTextFile, num, objTextFile, objFSO, strText | |
Const ForReading = 1 | |
If Wscript.Arguments.Count = 0 Then | |
Wscript.Echo "No text file was specified." | |
Wscript.Echo "Syntax: cscript collectsysteminfo.vbs file" | |
Wscript.quit 1 | |
Else | |
strTextFile = Wscript.Arguments(0) | |
End If | |
'Read server file | |
set objFSO = CreateObject("Scripting.FileSystemObject") | |
set objTextFile = objFSO.OpenTextFile(strTextFile, ForReading) | |
strText = objTextFile.ReadAll | |
objTextFile.Close | |
arrComputers = Split(strText, vbCrLf) | |
'Start the loops | |
for each strComputer in arrComputers | |
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") | |
' Save to CSV file | |
sLogFile = strComputer & ".csv" | |
sMsgFile = strComputer & ".txt" | |
set oLogObject = CreateObject("Scripting.FileSystemObject") | |
set oMsgOutput = oLogObject.CreateTextFile(sMsgFile) | |
If oLogObject.FileExists(sLogFile) Then | |
set oLogOutput = oLogObject.OpenTextFile _ | |
(sLogFile, 8, True) | |
Else | |
set oLogOutput = oLogObject.CreateTextFile(sLogFile) | |
oLogOutput.WriteLine "Name,Memory," & _ | |
"Manufacturer,Model,NumberofCores,ProcSpeed,Drive,DiskSize,DiskFree,NumNics" | |
End If | |
if err Then | |
if err.number = 462 Then | |
Wscript.Echo "Error: Could not find a machine named " & strComputer | |
oLogOutput.WriteLine strComputer | |
Wscript.Quit 2 | |
else | |
WScript.Echo "Error: " & err.number & " - " & err.description | |
Wscript.Quit 3 | |
end if | |
end if | |
' Get General information | |
Set colItems = objWMIService.ExecQuery( _ | |
"SELECT * FROM Win32_ComputerSystem",,48) | |
For Each objItem in colItems | |
logMsg = _ | |
objItem.Name & "," & _ | |
Cint ( ( objItem.TotalPhysicalMemory + 1023 ) / 1073741824 ) & "," & _ | |
objItem.Manufacturer & "," & _ | |
objItem.Model & "," | |
strMsg = strMsg & "Name: " & objItem.Name & vbCrLf _ | |
& "TotalPhysicalMemory: " & Cint ( ( objItem.TotalPhysicalMemory + 1023 ) / 1073741824 ) & " GB" & vbCrLf _ | |
& "Manufacturer: " & objItem.Manufacturer & vbCrLf _ | |
& "Model: " & objItem.Model & vbCrLf _ | |
Next | |
' Get Processor information | |
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor",,48) | |
For Each objItem in colItems | |
logMsg = logMsg & _ | |
objItem.NumberOfCores & "," & _ | |
objItem.MaxClockSpeed & "," | |
strMsg = strMsg _ | |
& "Number of Cores : " & objItem.NumberOfCores & vbCrLf _ | |
& "Maximum Clock Speed : " & Int ( ( objItem.MaxClockSpeed ) / 1000) & " Ghz" & vbCrLf & vbCrLf | |
Next | |
' Get Disk information | |
Set colItems = objWMIService.ExecQuery( "Select * from Win32_LogicalDisk where DriveType=3",,48) | |
For Each objItem in colItems | |
logMsg = logMsg & _ | |
objItem.Name & "," & _ | |
Int( ( objItem.Size + 536870912 ) / 1073741824 ) & "," & _ | |
Int( ( objItem.FreeSpace + 536870912 ) / 1073741824 ) & "," | |
strMsg = strMsg _ | |
& "Drive: " & objItem.Name & vbCrLf _ | |
& " Size: " & Int( ( objItem.Size + 536870912 ) / 1073741824 ) & " GB" & vbCrLf _ | |
& " Free: " & Int( ( objItem.FreeSpace + 536870912 ) / 1073741824 ) & " GB" & vbCrLf _ | |
& " % Free: " & Int( 100 * ( objItem.FreeSpace + 536870912 ) / objItem.Size ) & vbCrLf & vbCrLf | |
Next | |
' Get Network Adapter information | |
Set colItems = objWMIService.ExecQuery( "Select * from Win32_NetworkAdapter where NetConnectionStatus=2",,48) | |
For Each objItem in colItems | |
num = num +1 | |
next | |
strMsg = strMsg & "Number of Active Nics: " & num & vbCrLf & vbCrLf & vbCrLf | |
logMsg = logMsg & num | |
WScript.Echo strMsg | |
oLogOutput.WriteLine logMsg | |
oMsgOutput.WriteLine strMsg | |
oLogOutput.Close | |
oMsgOutput.Close | |
next | |
wscript.quit (0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment