'*****************************************************
'		Script Witten by Larry Heintz
'		Jan 2005 www.windowsadminscripts.com
' This script will connect to the AD Domain or Work
' Group name you enter and query and return the 
' following information for all the computers in the
' AD Domain or Work Group
'
' 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 /adwg:[AD Domain or Work Group Name]
' Optional Usage:
' To Save To File Usage: cscript hardware.vbs /adwg:[AD Domain or Work Group Name] > x:\pathtofile\filename.ext [c:\hardwareinfo.txt]
'*****************************************************
On Error Resume Next
' Dims stuff
Dim containername,container,computer
Dim objStdOut,args
Set objStdOut = Wscript.stdOut
Set args = Wscript.Arguments.Named
containername = args.Item("adwg")
' Connects to AD Domain or Work Group Name and gets all computers
set container = getobject("WinNT://" & containername)
' Puts all computers in array
container.filter = array("computer")

if wscript.arguments.count = 1 then
	for each computer in container
	wscript.echo "CPU,Memory,Hard Drive Information for " & ucase(computer.name)
	wscript.echo ""
	if not (errorChecking (computer.name)) then
			'// CPU Info
			wscript.echo "CPU Information:"
			wscript.echo "================"
			For each objCPU in GetObject("winmgmts:{impersonationLevel=impersonate}\\" & computer.name & "\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}\\" & computer.name & "\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}\\" & computer.name & "\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}\\" & computer.name & "\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 "------------------------------------------------"
	next
else
	objStdOut.Write "Usage: cscript hardware.vbs /adwg:[AD Domain or Work Group Name]"
	objStdOut.Write "To Save To File Usage: cscript hardware.vbs /adwg:[AD Domain or Work Group Name] > x:\pathtofile\filename.ext [c:\hardwareinfo.txt]"
	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 
