Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

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.
Avatar of Naitik Gamit
Naitik Gamit
Flag of India image

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
Avatar of Luis Diaz

ASKER

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.
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:
https://www.experts-exchange.com/questions/23836031/Hardware-inventory-collection.html

Rob.
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
Sure. It's all available from WMI. I'll see if I can make a start on getting it together tomorrow.

Rob.
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

Hello Aikimar,
Yes I am agree with you.

Thank you for your help.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Hi, did you change the first line to put valid computer names into the array?
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!
Excellent!