Skip to main content

Basic PC Info #Inventory

Batch Script 

Simple .bat file to fetch quite useful info of Computer in a user friendly output format .csv

PC-INFO.bat

----------------------------------------------------------------------------------------------------
@echo off
md OUTPUT
echo "%Date%" "%Time%"  >> Inventory.csv
echo Hostname, System Model, Operating System, Service Pack, Graphics Card, RAM (MB), CPU, Hard Disk, Storage (Bytes), Current Logged in User, System Location, IPv4/IPv6  >> Inventory.csv
echo " " >> Inventory.csv
@echo OFF
setlocal enableextensions
for /f %%s in ('type "Hosts.txt"') do call :PROCESS %%s
echo.
echo Fetching is Complete.
echo.
echo " " >> Inventory.csv
pause
goto :END

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

:WINNT
echo.
echo --------------------------------------

REM set variables
set hostname=
set ip=
set model=
set osname=
set sp=
set cpu_name=
set disk_drive=
set storage=
set graphic_card_name=
set adapter_ram=
set driver_version=
set logged_in_user=
set location=
setlocal ENABLEDELAYEDEXPANSION
set totalMem=
set availableMem=
set usedMem=
set IPv4=
set Domain=

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

REM Get Host Name
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 OS Get csname /value') do SET hostname=%%A

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

REM Get Computer OS
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 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 /node:%1 os get ServicePackMajorVersion /value') do SET sp=%%A

REM Get Computer CPU
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 cpu get name /value') do SET cpu_name=%%A

REM Get Computer Logged in User
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 computersystem get username /value') do SET logged_in_user=%%A

REM Get Graphic Card Name
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 path win32_VideoController get name /value') do SET graphic_card_name=%%A

REM Get Graphic Card RAM
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 path win32_VideoController get adapterram /value') do SET adapter_ram=%%A

REM Get Graphic Card Version
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 path win32_VideoController get driverversion /value') do SET driver_version=%%A

REM Get Hard Disk
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 diskdrive get model /value') do
(set "disk_drive=!disk_drive! ; %%A") 
REM Get Storage
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 diskdrive get size /value') do (set "storage=!storage! ; %%A")
REM Get IP
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 nicconfig where "IPEnabled  = True" get ipaddress /format:csv /value') do SET ip=%%A

REM Get Location
FOR /F "tokens=2 delims='='" %%A in ('wmic /node:%1 environment where "name = 'location'" get variablevalue /value') do SET Location=%%A
FOR /F "tokens=* delims='='" %%A in ("%location%") do SET Location="%%A"

REM Get Memory
FOR /F "tokens=4" %%a in ('systeminfo /s %1 ^| findstr Total') do set totalMem=%%a
set totalMem=%totalMem:,=%
echo.

echo ----------------------------------------------------------------
echo Host Name        : %hostname%
echo Model            : %model%
echo Operating System    : %osname%
echo Service Pack        : %sp%
echo CPU            : %cpu_name%
echo Memory            : %totalMem%
echo Hard Disk        :%disk_drive:~2%
echo Storage            :%storage:~2%
echo Logged in User        : %logged_in_user%
echo Graphics Adapter RAM    : %adapter_ram%
echo Graphics Driver Version    : %driver_version%
echo Graphic Card Name    : %graphic_card_name%
echo IP Address        : %ip%
echo Location        : %location%
echo -----------------------------------------------------------------

REM Generate file
SET file="OUTPUT\%1%.txt"
echo ------------------"" %DATE% %TIME% ""--------------- >> %file%
echo ---------------------------------------------------------------------- >> %file%

echo Details For        : %hostname% >> %file%
echo Model            : %model% >> %file%
echo Operating System        : %osname% >> %file%
echo Service Pack        : %sp% >> %file%
echo Logged in User        : %logged_in_user%>>%file%
echo Memory            : %totalMem% MB >> %file%
echo CPU            : %cpu_name%>>%file%
echo Storage            :%storage:~2% Bytes >> %file%
echo Hard Disk            :%disk_drive:~2% >> %file%
echo Graphics Adapter RAM    : %adapter_ram% Bytes >> %file%
echo Graphics Driver Version    : %driver_version% >> %file%
echo Graphic Card Name        : %graphic_card_name% >> %file%
echo IP Address        : %ip% >> %file%
echo Location            : %location% >> %file%

echo ---------------------------------------------------------------------- >> %file%
echo  %hostname%, %model%, %osname%, SP %sp%, %graphic_card_name%, %totalMem%, %cpu_name%,%disk_drive:~2%,%storage:~2%, User: %logged_in_user%, %location%, %ip%    >> Inventory.csv
REM systeminfo /s %1 | findstr /c:"Host Name" /c:"OS Name" /c:"OS Version"  /c:"System Model" /c:"System type" /c:"Total Physical Memory" 

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

:END
goto :EOF

:END
endlocal

___________________________________________________________________________________

Copy above code and paste it on notepad and save it as .bat file
create one Hosts.txt file put required computer list

Format to be followed @ Hosts.txt
IP1 or HOSTNAME1
IP2 or HOSTNAME2
.
.
.
.

Comments

Popular posts from this blog

Disk Drive Info

Disk Drive Information of a Computer HARD_DRIVE_INFO.bat ____________________________________________________________________ @echo off md OUTPUT echo. echo Fetching data................. echo. @echo OFF for /f %%s in ('type "Hosts.txt"') do call :PROCESS %%s echo. echo Fetching is Complete. Please refer "OUTPUT\" for the data. echo. pause goto :END :PROCESS @echo off if %os%==Windows_NT goto WINNT :WINNT ( echo. echo %1%, Drive, Free Space, Total Size @echo off for /f "tokens=1-3" %%a in ('WMIC /node:%1 LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"') do @echo wsh.echo ",%%b," ^& FormatNumber^(cdbl^(%%a^)/1024/1024/1024, 2, , , vbFalse^)^& " GB," ^& FormatNumber^(cdbl^(%%c^)/1024/1024/1024, 2, , , vbFalse^)^& " GB" > %temp%\tmp.vbs & @if not "%%c"=="" @echo( & @cscript //nologo %temp%\tmp.vbs & del %temp%\tmp.vbs)  >> OUTP