How to get current system status?

Hello,
What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc) of one of my virtual machines?
Bat?
Vbscript?
Powershell?
Python?

Can someone  share me a code for this?

Thank you in advance.
LVL 1
LD16Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Naitik GamitSoftware DeveloperCommented:
psutil in python is best way to retrieving information onrunning processes and system utilization (CPU, memory, disks, network).

below link provide full information with code:
https://pypi.python.org/pypi/psutil
0
LD16Author Commented:
Hello,

Thank you for this recommendations. I don't know how to run python scripts, could you please help me with this?
Thank you again for your help.
0
RobSampsonCommented:
Hi, batch, VBScript, and Powershell can all make use of WMI queries to gather system information (I don't know about Python because I've never used it).

If you search for "Powershell system inventory" or "VBScript system inventory" you will see many scripts of varying complexity that gather this information.

Here's one:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23836031.html

Rob.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

LD16Author Commented:
Hello Rob,

Thank you for this recommendation.
I had a look to your solution of question Q_23836031.html however I doesn't meet my requirement which is more simple like this one.

The VBscript should export a systeminfo & ip address of the machine.txt:

With the following information

--------------------------------------------
Details For: IP address
Manufacturer:
Model:
Serial Number:
Operating System:
C:\ Total:
C:\ Avail:
Total Memory: ,=
Used  Memory: 0
Computer Processor:  
Service Pack:
--------------------------------------------

Thank you in advance for your help
0
RobSampsonCommented:
Sure. It's all available from WMI. I'll see if I can make a start on getting it together tomorrow.

Rob.
0
LD16Author Commented:
Thank you so much Rob!

I found this code however the disk storage and memory is not working well when I launch this from a server and I don't have the IP address variable set up.


@echo off
if %os%==Windows_NT goto WINNT
goto NOCON

:WINNT
echo .Using a Windows NT based system
echo ..%computername%

REM set variables
set system=
set manufacturer=
set model=
set serialnumber=
set osname=
set sp=
setlocal ENABLEDELAYEDEXPANSION
set "volume=C:"
set totalMem=
set availableMem=
set usedMem=

echo Getting data [Computer: %computername%]...
echo Please Wait....

REM Get Computer Name
FOR /F "tokens=2 delims='='" %%A in ('wmic OS Get csname /value') do SET system=%%A

REM Get Computer Manufacturer
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Manufacturer /value') do SET manufacturer=%%A

REM Get Computer Model
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

REM Get Computer Serial Number
FOR /F "tokens=2 delims='='" %%A in ('wmic Bios Get SerialNumber /value') do SET serialnumber=%%A

REM Get Computer OS
FOR /F "tokens=2 delims='='" %%A in ('wmic os get Name /value') do SET osname=%%A
FOR /F "tokens=1 delims='|'" %%A in ("%osname%") do SET osname=%%A

REM Get Computer OS SP
FOR /F "tokens=2 delims='='" %%A in ('wmic os get ServicePackMajorVersion /value') do SET sp=%%A

REM Get Memory
FOR /F "tokens=4" %%a in ('systeminfo ^| findstr Physical') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a)
set totalMem=%totalMem:,=%
set availableMem=%availableMem:,=%
set /a usedMem=totalMem-availableMem

FOR /f "tokens=1*delims=:" %%i IN ('fsutil volume diskfree %volume%') DO (
    SET "diskfree=!disktotal!"
    SET "disktotal=!diskavail!"
    SET "diskavail=%%j"
)
FOR /f "tokens=1,2" %%i IN ("%disktotal% %diskavail%") DO SET "disktotal=%%i"& SET "diskavail=%%j"

echo done!

echo --------------------------------------------
echo System Name: %system%
echo Manufacturer: %manufacturer%
echo Model: %model%
echo Serial Number: %serialnumber%
echo Operating System: %osname%
echo C:\ Total: %disktotal:~0,-9% GB
echo C:\ Avail: %diskavail:~0,-9% GB
echo Total Memory: %totalMem%
echo Used  Memory: %usedMem%
echo Computer Processor: %processor_architecture%
echo Service Pack: %sp%
echo --------------------------------------------

REM Generate file
SET file="%~dp0%computername%.txt"
echo -------------------------------------------- >> %file%
echo Details For: %system% >> %file%
echo Manufacturer: %manufacturer% >> %file%
echo Model: %model% >> %file%
echo Serial Number: %serialnumber% >> %file%
echo Operating System: %osname% >> %file%
echo C:\ Total: %disktotal:~0,-9% GB >> %file%
echo C:\ Avail: %diskavail:~0,-9% GB >> %file%
echo Total Memory: %totalMem% >> %file%
echo Used  Memory: %usedMem% >> %file%
echo Computer Processor: %processor_architecture% >> %file%
echo Service Pack: %sp% >> %file%
echo -------------------------------------------- >> %file%

REM request user to push any key to continue
pause

goto END

:NOCON
echo Error...Invalid Operating System...
echo Error...No actions were made...
goto END

:END

Open in new window

0
LD16Author Commented:
Hello Aikimar,
Yes I am agree with you.

Thank you for your help.
0
RobSampsonCommented:
Hi, here is a script that should get you the information you specified.

Regards,

Rob.

arrComputers = Array("PC1","PC2")
strOutputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "HardwareAudit.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objNetwork = CreateObject("WScript.Network")

Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
objOutput.WriteLine """Computername"",""IP Address"",""Manufacturer"",""Model"",""Serial Number"",""C:\ Total (GB)"",""C:\ Avail (GB)"",""Memory Total (GB)"",""Memory Avail (GB)"",""Processor"",""Operating System"",""OS Version"",""Service Pack"""

For Each strComputer In arrComputers
	' Create the WMI session
	If Ping(strComputer) = True Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		
		' Get computername, manufacturer, and model
		Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
		For Each objComputer in colComputer
		    strHostName = objComputer.Name
		    strManufacturer = objComputer.Manufacturer
		    strModel = objComputer.Model
		Next
		
		'Get IP Address
		Set colComputerIP = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
		strIPAddress = ""
		For Each IPConfig in colComputerIP
			If Not IsNull(IPConfig.IPAddress) Then 
				'strIPAddress = strIPAddress & IPConfig.Description & ": "
		        For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
		        	If IPConfig.IPAddress(intIPCount) <> "0.0.0.0" And InStr(IPConfig.IPAddress(intIPCount), ".") > 0 Then
						If strIPAddress = "" Then
							strIPAddress = IPConfig.IPAddress(intIPCount)
						Else
							strIPAddress = strIPAddress & ";" & IPConfig.IPAddress(intIPCount)
						End If
					End If
				Next
			End If
		Next
	
		' Get the serial number
		Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
		For Each objItem In colItems
			strSerialNumber = Trim(objItem.SerialNumber)
		Next
		
		' Get OS information
		Set colSystemInfo = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
		For Each objItem in colSystemInfo
		     strOS_Caption = objItem.Caption
		     strOS_SPVersion = objItem.CSDVersion
		     strOS_VerNumber = objItem.Version
		     strOS_Memory = Trim(FormatNumber(objItem.TotalVisibleMemorySize/1024,0))
		Next
	
		' Get available memory
		Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Memory",,48)
		For Each objItem in colItems
			strAvailableMemory = Trim(Round(objItem.AvailableBytes / (1024 *1024 * 1024),2))
		Next
		
		' Get CPU Details
		Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
		strCPUDetails = ""
		For Each objItem In colItems
			If strCPUDetails = "" Then
				strCPUDetails = Trim(objItem.Name)
			Else
				strCPUDetails = strCPUDeatils & ";" & Trim(objItem.Name)
			End If
		Next
	
		' Get Hard Drive Size
		Dim strDiskSizes
		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 3 And Name='C:'")
		For Each objItem In colItems
		   	strDiskSize = Trim(Round(objItem.Size / 1024 / 1024 / 1024, 2))
		   	strDiskFreeSpace = Trim(Round(objItem.FreeSpace / 1024 / 1024 / 1024, 2))
		Next
		
		objOutput.WriteLine """" & strHostName & """,""" & strIPAddress & """,""" & strManufacturer & """,""" & strModel & """,""" & strSerialNumber & """,""" & strDiskSize & """,""" & strDiskFreeSpace & """,""" & strOS_Memory & """,""" & strAvailableMemory & """,""" & strCPUDetails & """,""" & strOS_Caption & """,""" & strOS_VerNumber & """,""" & strOS_SPVersion & """"
	End If
Next

objOutput.Close
Set objOutput = Nothing
WScript.Echo "Done. Please see " & strOutputFile

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
Hello Rob,

I launched your script however I got a a file with just the headers and any info.
The VM that I used is in 64 I don't know if this has an impact on the script.

Thank you in advance.
0
RobSampsonCommented:
Hi, did you change the first line to put valid computer names into the array?
0
LD16Author Commented:
It works perfectly, this is a great script as I can launch from my computer and put multiple machine names and got a compiled file with the various information!
0
LD16Author Commented:
Excellent!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.