Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

(If this should be on stackoverflow just tell me...but it seemed more fitting here)

I found the script below online from this site: http://forums.webhostautomation.com/showthread.php?t=8667

Can someone please assist in adding (if possible) the following queries as well:

*# of power supplies

*Operating System and service pack level

*# of NICs and what type of NIC (Gb/etc.)

I'm not very good at scripting and once I started down the road of adding these features I ended up breaking the script.

Thank you in advance!

'*****************************************************
'   	Script Witten by Larry Heintz
'   	Jan 2005 www.larryheintz.com
' This script will connect to the computer name you
' enter and query and return the following information
'
' CPU:
'   - CPU Speed MHZ
'   - CPU Manufacture
'   - CPU Type
'   - CPU Current Load
'
' Memory
'   - Memory Bank
'   - Memory Stick Size MB
'   - Memory Speed MHZ
'   - Memory Type
'
' Hard Drive
'   - HD Model
'   - HD Size GB
'   - HD # of Partions
'   - HD Type
'   - Drive Letter
'   - Used Space
'   - Free Space
'   - Size of Partion
'   - Free Space %
'
' Script Usage:
' cscript hardware.vbs /computer:[Computer Name]
'*****************************************************
On Error Resume Next
' Dims stuff
Dim objStdOut, args
Dim servername
' Set Stuff
Set objStdOut = WScript.stdOut
Set args = WScript.Arguments.Named
servername = Trim(args.Item("computer"))

If WScript.arguments.count = 1 Then
    WScript.echo "CPU,Memory,Hard Drive Information for " & UCase(servername)
    WScript.echo ""
    If Not (errorChecking(servername)) Then
    	'// CPU Info
    	WScript.echo "CPU Information:"
    	WScript.echo "================"
    	For Each objCPU In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_Processor")
    		Select Case objCPU.Family
    			Case 2
    				cputype = "Unknown"
    			Case 11
    				cputype = "Pentium brand"
    			Case 12
    				cputype = "Pentium Pro"
    			Case 13
    				cputype = "Pentium II"
    			Case 14
    				cputype = "Pentium processor with MMX technology"
    			Case 15
    				cputype = "Celeron "
    			Case 16
    				cputype = "Pentium II Xeon"
    			Case 17
    				cputype = "Pentium III"
    			Case 28
    				cputype = "AMD Athlon Processor Family"
    			Case 29
    				cputype = "AMD Duron Processor"
    			Case 30
    				cputype = "AMD2900 Family"
    			Case 31
    				cputype = "K6-2+"
    			Case 130
    				cputype = "Itanium Processor"
    			Case 176
    				cputype = "Pentium III Xeon"
    			Case 177
    				cputype = "Pentium III Processor with Intel SpeedStep Technology"
    			Case 178
    				cputype = "Pentium 4"
    			Case 179
    				cputype = "Intel Xeon"
    			Case 181
    				cputype = "Intel Xeon processor MP"
    			Case 182
    				cputype = "AMD AthlonXP Family"
    			Case 183
    				cputype = "AMD AthlonMP Family"
    			Case 184
    				cputype = "Intel Itanium 2"
    			Case 185
    				cputype = "AMD Opteron™ Family"
    		End Select
    		WScript.echo " CPU MHZ: " & objCPU.CurrentClockSpeed
    		WScript.echo " CPU Manufacture: " & objCPU.Manufacturer
    		WScript.echo " CPU Type: " & cputype
    		WScript.echo " CPU Current Load: " & objCPU.LoadPercentage & "%"
    	Next
    	WScript.echo ""
    	Set objCPU = Nothing

    	'// Memory Info
    	WScript.echo "Memory Information:"
    	WScript.echo "==================="
    	For Each objMem In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_PhysicalMemory")
    		Select Case objMem.MemoryType
    			Case 0
    				rtype = "Unknown"
    			Case 1
    				rtype = "Other"
    			Case 2
    				rtype = "DRAM"
    			Case 3
    				rtype = "Synchronous DRAM"
    			Case 4
    				rtype = "Cache DRAM"
    			Case 5
    				rtype = "EDO"
    			Case 6
    				rtype = "EDRAM"
    			Case 7
    				rtype = "VRAM"
    			Case 8
    				rtype = "SRAM"
    			Case 9
    				rtype = "RAM"
    			Case 10
    				rtype = "ROM"
    			Case 11
    				rtype = "Flash"
    			Case 12
    				rtype = "EEPROM"
    			Case 13
    				rtype = "FEPROM"
    			Case 14
    				rtype = "EPROM"
    			Case 15
    				rtype = "CDRAM"
    			Case 16
    				rtype = "3DRAM"
    			Case 17
    				rtype = "SDRAM"
    			Case 18
    				rtype = "SGRAM"
    			Case 19
    				rtype = "RDRAM"
    			Case 20
    				rtype = "DDR"
    		End Select
    		WScript.echo " Memory Bank: " & objMem.BankLabel
    		WScript.echo " Memory Size: " & objMem.Capacity / 1024 / 1024 & " MB"
    		WScript.echo " Memory Speed: " & objMem.Speed & " MHZ"
    		WScript.echo " Memory Type: " & rtype
    		WScript.echo ""
    	Next
    	WScript.echo ""
    	Set objMem = Nothing

    	'// Hard Drive Info
    	WScript.echo "Hard Drive Information:"
    	WScript.echo "======================="
    	For Each objHDInfo In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_DiskDrive")
    		WScript.echo " Hard Drive Model: " & objHDInfo.Model
    		WScript.echo " Hard Drive Size: " & CLng(objHDInfo.Size / 1024 / 1024 / 1024) & " GB"
    		WScript.echo " # of Partitions: " & objHDInfo.Partitions
    		WScript.echo " Hard Drive Type: " & objHDInfo.InterfaceType
    		WScript.echo ""
    	Next
    	WScript.echo ""
    	Set objHDinfo = Nothing

    	For Each objDisk In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_LogicalDisk Where DriveType = '3'")
    		freespace = Left(objDisk.freespace / 1024 / 1024 / 1024, 4)
    		totalspace = Left(objDisk.size / 1024 / 1024 / 1024, 4)
    		usedspace = Left(totalspace / freespace, 4)
    		freeperct = Left(100 / usedspace, 2)
    		WScript.echo " Drive: " & objDisk.deviceid
    		WScript.echo " Used Space: " & usedspace & " GB"
    		WScript.echo " Free Space: " & freespace & " GB"
    		WScript.echo " Total Space: " & totalspace & " GB"
    		WScript.echo " Free: " & freeperct & "%"
    		WScript.echo ""
    	Next
    	Set objDisk = Nothing
    End If
    WScript.echo "------------------------------------------------"
Else
    objStdOut.Write "Usage: cscript hardware.vbs /computer:[Computer Name]"
    objStdOut.close
    WScript.quit
End If

' Error Checking Function
Function errorChecking(ComputerName) 
    errorChecking = False 
    If err.number <> 0 Then 
    	If err.number = "462" Then
    		WScript.echo ComputerName & ",Error,Unable to connect"
    		err.Clear() 
    		errorChecking = True
    	ElseIf err.number = "70" Then   'General access denied error
    		WScript.echo ComputerName & ",Error,Permission Denied while trying to connect."
    		err.Clear() 
    		errorChecking = True
    	ElseIf err.number = "451" Then 'HEX Error is: 1C3
    		err.Clear() 
    		errorChecking = True
    	ElseIf err.number = "-2147023174" Then   'The RPC server is unavailable.
    		WScript.echo ComputerName & ",Error,Unable to connect error number -2147023174."
    		err.Clear() 
    		errorChecking = True
    	ElseIf err.number = "-2147023836" Then
    		WScript.echo ComputerName & ",Error,Unable to connect error number --2147023836."
    		err.Clear() 
    		errorChecking = True
    	ElseIf err.number = "-2147022986" Then
    		WScript.echo ComputerName & ",Error,Unable to connect error number -2147022986."
    		err.Clear() 
    		errorChecking = True
    	Else
    		WScript.echo "Error is: " & err.number
    		WScript.echo "HEX Error is: " & Hex(err.number)
    		WScript.echo "Desc. is: " & err.Description
    		WScript.echo "Source is: " & err.Source
    		err.Clear()
    	End If 
    End If 
End Function
share|improve this question
1  
This type of script is well in the realm of sysadmin duties. Ok by me to leave it here. –  squillman Sep 15 '09 at 18:30
    
There's a windows version of Cfg2Html (available from cfg2html.com ) that generates a ton of useful info. You'll have to join the yahoo group to grab it, and then you'll want the windows version of the script- the unix variations are pretty great, so they may include the info you're looking for here. –  Tim Howland Sep 15 '09 at 19:01

5 Answers 5

up vote 4 down vote accepted

Have a go at this. New info is added at the bottom of the script. One caveat, NIC (ndis) link speed is given by a different provider than the other NIC properties. As such there are 2 new sections for NIC info: NIC Instance Information and NIC Link Information. Each enumerates all the NICs in your machine and gives the relevant info.

'*****************************************************
'       Script Witten by Larry Heintz
'       Jan 2005 www.larryheintz.com
'       Modified Sep 2009 by Shawn Quillman for use on ServerFault.com
' This script will connect to the computer name you
' enter and query and return the following information
'
' CPU:
'   - CPU Speed MHZ
'   - CPU Manufacture
'   - CPU Type
'   - CPU Current Load
'
' Memory
'   - Memory Bank
'   - Memory Stick Size MB
'   - Memory Speed MHZ
'   - Memory Type
'
' Hard Drive
'   - HD Model
'   - HD Size GB
'   - HD # of Partions
'   - HD Type
'   - Drive Letter
'   - Used Space
'   - Free Space
'   - Size of Partion
'   - Free Space %
'
' Script Usage:
' cscript hardware.vbs /computer:[Computer Name]
'*****************************************************
On Error Resume Next
' Dims stuff
Dim objStdOut, args
Dim servername
' Set Stuff
Set objStdOut = WScript.stdOut
Set args = WScript.Arguments.Named
servername = Trim(args.Item("computer"))

If WScript.arguments.count = 1 Then
    WScript.echo "CPU,Memory,Hard Drive Information for " & UCase(servername)
    WScript.echo ""
    If Not (errorChecking(servername)) Then
        '// CPU Info
        WScript.echo "CPU Information:"
        WScript.echo "================"
        For Each objCPU In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_Processor")
                Select Case objCPU.Family
                        Case 2
                                cputype = "Unknown"
                        Case 11
                                cputype = "Pentium brand"
                        Case 12
                                cputype = "Pentium Pro"
                        Case 13
                                cputype = "Pentium II"
                        Case 14
                                cputype = "Pentium processor with MMX technology"
                        Case 15
                                cputype = "Celeron "
                        Case 16
                                cputype = "Pentium II Xeon"
                        Case 17
                                cputype = "Pentium III"
                        Case 28
                                cputype = "AMD Athlon Processor Family"
                        Case 29
                                cputype = "AMD Duron Processor"
                        Case 30
                                cputype = "AMD2900 Family"
                        Case 31
                                cputype = "K6-2+"
                        Case 130
                                cputype = "Itanium Processor"
                        Case 176
                                cputype = "Pentium III Xeon"
                        Case 177
                                cputype = "Pentium III Processor with Intel SpeedStep Technology"
                        Case 178
                                cputype = "Pentium 4"
                        Case 179
                                cputype = "Intel Xeon"
                        Case 181
                                cputype = "Intel Xeon processor MP"
                        Case 182
                                cputype = "AMD AthlonXP Family"
                        Case 183
                                cputype = "AMD AthlonMP Family"
                        Case 184
                                cputype = "Intel Itanium 2"
                        Case 185
                                cputype = "AMD Opteron? Family"
                End Select
                WScript.echo " CPU MHZ: " & objCPU.CurrentClockSpeed
                WScript.echo " CPU Manufacture: " & objCPU.Manufacturer
                WScript.echo " CPU Type: " & cputype
                WScript.echo " CPU Current Load: " & objCPU.LoadPercentage & "%"
        Next
        WScript.echo ""
        Set objCPU = Nothing

        '// Memory Info
        WScript.echo "Memory Information:"
        WScript.echo "==================="
        For Each objMem In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_PhysicalMemory")
                Select Case objMem.MemoryType
                        Case 0
                                rtype = "Unknown"
                        Case 1
                                rtype = "Other"
                        Case 2
                                rtype = "DRAM"
                        Case 3
                                rtype = "Synchronous DRAM"
                        Case 4
                                rtype = "Cache DRAM"
                        Case 5
                                rtype = "EDO"
                        Case 6
                                rtype = "EDRAM"
                        Case 7
                                rtype = "VRAM"
                        Case 8
                                rtype = "SRAM"
                        Case 9
                                rtype = "RAM"
                        Case 10
                                rtype = "ROM"
                        Case 11
                                rtype = "Flash"
                        Case 12
                                rtype = "EEPROM"
                        Case 13
                                rtype = "FEPROM"
                        Case 14
                                rtype = "EPROM"
                        Case 15
                                rtype = "CDRAM"
                        Case 16
                                rtype = "3DRAM"
                        Case 17
                                rtype = "SDRAM"
                        Case 18
                                rtype = "SGRAM"
                        Case 19
                                rtype = "RDRAM"
                        Case 20
                                rtype = "DDR"
                End Select
                WScript.echo " Memory Bank: " & objMem.BankLabel
                WScript.echo " Memory Size: " & objMem.Capacity / 1024 / 1024 & " MB"
                WScript.echo " Memory Speed: " & objMem.Speed & " MHZ"
                WScript.echo " Memory Type: " & rtype
                WScript.echo ""
        Next
        WScript.echo ""
        Set objMem = Nothing

        '// Hard Drive Info
        WScript.echo "Hard Drive Information:"
        WScript.echo "======================="
        For Each objHDInfo In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_DiskDrive")
                WScript.echo " Hard Drive Model: " & objHDInfo.Model
                WScript.echo " Hard Drive Size: " & CLng(objHDInfo.Size / 1024 / 1024 / 1024) & " GB"
                WScript.echo " # of Partitions: " & objHDInfo.Partitions
                WScript.echo " Hard Drive Type: " & objHDInfo.InterfaceType
                WScript.echo ""
        Next
        WScript.echo ""
        Set objHDinfo = Nothing

        For Each objDisk In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_LogicalDisk Where DriveType = '3'")
                freespace = Left(objDisk.freespace / 1024 / 1024 / 1024, 4)
                totalspace = Left(objDisk.size / 1024 / 1024 / 1024, 4)
                usedspace = Left(totalspace / freespace, 4)
                freeperct = Left(100 / usedspace, 2)
                WScript.echo " Drive: " & objDisk.deviceid
                WScript.echo " Used Space: " & usedspace & " GB"
                WScript.echo " Free Space: " & freespace & " GB"
                WScript.echo " Total Space: " & totalspace & " GB"
                WScript.echo " Free: " & freeperct & "%"
                WScript.echo ""
        Next
        Set objDisk = Nothing

        '// Operating System and Service Pack
        WScript.echo "Operating System Information:"
        WScript.echo "======================="
        For Each objOSInfo In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_OperatingSystem")
                WScript.echo " Operating System: " & left(objOSInfo.Name,instr(objOSInfo.Name,"|")-1)
    			WScript.echo " Service Pack Major Version: " & objOSInfo.ServicePackMajorVersion
    			WScript.echo " Service Pack Minor Version: " & objOSInfo.ServicePackMinorVersion
                WScript.echo ""
        Next
        WScript.echo ""
        Set objOSinfo = Nothing

        '// NIC Info
        WScript.echo "NIC Instance Information:"
        WScript.echo "======================="
        For Each objNICInfo In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_NetworkAdapterConfiguration")
                WScript.echo " Caption (Name of NIC): " & objNICInfo.Caption
    			WScript.echo "     MAC Address: " & objNICInfo.MACAddress
    			WScript.echo "     IP Address(es): " & Join(objNICInfo.IPAddress,", ")
    			set objWMI = GetObject("winmgmts:\\" & servername & "\root\WMI")
    			set colNICProps = objWMI.ExecQuery("SELECT * FROM MSNdis_LinkSpeed")
    			for each objProp in colNICProps
    					WScript.echo "     Active:" & objProp.Active
    					WScript.echo "     Link Speed:" & objProp.NdisLinkSpeed
    					WScript.echo "     Instance Name:" & objProp.InstanceName & " - " & objNICInfo.Caption
    			next
                WScript.echo ""
        Next
        WScript.echo ""
        Set objNICinfo = Nothing

        '// NIC Info
        WScript.echo "NIC Link Information:"
        WScript.echo "======================="
    	set objWMI = GetObject("winmgmts:\\" & servername & "\root\WMI")
    	set colNICProps = objWMI.ExecQuery("SELECT * FROM MSNdis_LinkSpeed")
    	for each objProp in colNICProps
    			WScript.echo " Instance Name:" & objProp.InstanceName 
    			WScript.echo "     Active:" & objProp.Active
    			WScript.echo "     Link Speed:" & objProp.NdisLinkSpeed & " bps"
    	next
    	WScript.echo ""
        WScript.echo ""
        Set objNICinfo = Nothing

        '// Powersupply Info
        WScript.echo "Power Supply Information:"
        WScript.echo "======================="
    	intPSCount = 0
        For Each objPSInfo In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_PowerSupply")
    			intPSCount = intPSCount + 1
        Next
    	WScript.echo "     Number of Power Supplies: " & intPSCount
    	WScript.echo ""
        WScript.echo ""
        Set objPSinfo = Nothing
    End If
    WScript.echo "------------------------------------------------"
Else
    objStdOut.Write "Usage: cscript hardware.vbs /computer:[Computer Name]"
    objStdOut.close
    WScript.quit
End If

' Error Checking Function
Function errorChecking(ComputerName) 
    errorChecking = False 
    If err.number <> 0 Then 
        If err.number = "462" Then
                WScript.echo ComputerName & ",Error,Unable to connect"
                err.Clear() 
                errorChecking = True
        ElseIf err.number = "70" Then   'General access denied error
                WScript.echo ComputerName & ",Error,Permission Denied while trying to connect."
                err.Clear() 
                errorChecking = True
        ElseIf err.number = "451" Then 'HEX Error is: 1C3
                err.Clear() 
                errorChecking = True
        ElseIf err.number = "-2147023174" Then   'The RPC server is unavailable.
                WScript.echo ComputerName & ",Error,Unable to connect error number -2147023174."
                err.Clear() 
                errorChecking = True
        ElseIf err.number = "-2147023836" Then
                WScript.echo ComputerName & ",Error,Unable to connect error number --2147023836."
                err.Clear() 
                errorChecking = True
        ElseIf err.number = "-2147022986" Then
                WScript.echo ComputerName & ",Error,Unable to connect error number -2147022986."
                err.Clear() 
                errorChecking = True
        Else
                WScript.echo "Error is: " & err.number
                WScript.echo "HEX Error is: " & Hex(err.number)
                WScript.echo "Desc. is: " & err.Description
                WScript.echo "Source is: " & err.Source
                err.Clear()
        End If 
    End If 
End Function
share|improve this answer
    
I love you...in a man crush sort of way. Thanks that worked beyond perfectly! –  TheCleaner Sep 15 '09 at 20:14
    
Whoah, let's not get carried away now :) (heh) –  squillman Sep 16 '09 at 16:29

Documentation on retrieving information via WMI

Classes and Properties:

OS (Win32_OperatingSystem)

  • Name
  • CSDVersion
  • BuildNumber
  • Version
  • ServicePackMajorVersion
  • ServicePackMinorVersion

NIC (Win32_NetworkAdapter)

  • Manufacturer
  • ProductName
  • MaxSpeed
  • Speed
  • AdapterType

Power Supply (Current Sensor) (Win32_CurrentProbe)

Examples:

A repository of WMI scripts

share|improve this answer
    
+1 - added the link for the repository for future reference –  TheCleaner Sep 15 '09 at 20:15
    
BTW - I got the number of power supplies from Win32_PowerSupply –  squillman Sep 16 '09 at 16:24

Microsoft's Scriptomatic v2 Is one of my favorite tools. I is like having the whole WMI API in my pocket.
It will write the script you need for you:)

http://www.microsoft.com/downloads/details.aspx?familyid=09DFC342-648B-4119-B7EB-783B0F7D1178&displaylang=en

share|improve this answer
    
Gave you +1 cause I forgot about this program and it will help in the future –  TheCleaner Sep 15 '09 at 20:15
    
If you like the Scriptomatic2, there is now a PowerShell Scriptomatic. It's the way I learned how to use PowerShell. microsoft.com/downloads/… –  BLAKE Sep 16 '09 at 4:25

Microsoft's Scriptomatic utility generates code snippets based on all WMI (Windows Management Instrumentation) providers available on your system (which is what your existing script is using). Incidentally, the language that the script above is written in is VBScript, so you will want to choose that as the language to use for code output by Scriptomatic.

Enjoy!

share|improve this answer

you could also try taking a look at sydi-server. it's already made with some pretty nice features. maybe at least looking at the script to see if it has something else you may want.

http://sydiproject.com/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.