Get computer specs, and save the the results automatically

3.5k Views Asked by At

I have added YOUR-COMMAND | Out-File -FilePath c:\PATH\TO\FOLDER\OUTPUT.txt after each command but still, no file was created with the pc specs. After saving the script in the batch file, the cmd is popping up and the specs are being shown, but I need to have it automatically saved on the desktop.

@echo off
echo Checking your system info, Please wait...
ipconfig | find /i "IPv4" 
systeminfo | findstr /c:"Host Name" 
systeminfo | findstr /c:"OS Name" 
systeminfo | findstr /c:"System type" 
systeminfo | findstr /c:"Domain" 
systeminfo | findstr /c:"OS Version" 
systeminfo | findstr /c:"System Model"
systeminfo | findstr /c:"Total Physical Memory" 
systeminfo | findstr /c:"System Manufacturer" 

echo.
echo Service Tag:
wmic bios get serialnumber

echo.
echo Hard Drive Space:
wmic diskdrive get Name, Manufacturer, Model, InterfaceType, MediaType, SerialNumber, size

echo.
echo CPU:
wmic cpu list brief

echo.
echo Memory:
wmic MemoryChip get BankLabel, Capacity, MemoryType, TypeDetail, Speed

echo.
echo BaseBoard:
wmic baseboard get product,Manufacturer,version,serialnumber

pause
2

There are 2 best solutions below

1
On

As per Compo's advice, a much more efficient approach is to enact multiple findstr commands on a singular instance of Systeminfo. The below uses a macro to enact and format the output of successful findstr commands, with each string to be found supplied to the macro via substring modification. The For /F loop that runs the system info command is wrapped in parentheses to enable redirection to the .txt file of the full command output rather than performing multiiple write actions.

The same approach regarding macro usage can be applied to the wmic commands.

@Echo Off & Setlocal DISABLEdelayedexpansion
@Echo Off & Setlocal DISABLEdelayedexpansion
CD "%~dp0"
 Set "FSTR=( Echo/"%%~A" | %__AppDir__%findstr.exe /LIC:"$Str" > Nul 2> Nul ) && (Set "$$Str=%%~A" & <Nul Set /P "=$Str=" & <Nul Set/P "=!$$Str:*:=!" &Echo/)"
 Set "Wmic=For %%n in (1 2)Do if %%n==2 ( >>"%~n0_Outfile.txt" Echo/!Field!:&For /F "UsebackQ Delims=" %%G in (`" wmic Attrib /Format:Value 2^> Nul "`)Do If Not "%%~G" == "" For /F "Delims=" %%i in ("%%~G")Do ( 1>> "%~n0_outfile.txt" Echo/%%~i))Else Set Field="
Setlocal EnableDelayedExpansion
(For /F "Delims=" %%A in ('%__AppDir__%systeminfo.exe /FO List')Do (
 %FSTR:$Str=Host Name%
 %FSTR:$Str=OS Name%
 %FSTR:$Str=System type%
 %FSTR:$Str=System Model%
 %FSTR:$Str=Total Physical Memory%
 %FSTR:$Str=System Manufacturer%
))>"%~n0_outfile.txt"
 %WMIC:Attrib=bios get serialnumber%Bios
 %WMIC:Attrib=diskdrive get Name, Manufacturer, Model, InterfaceType, MediaType, SerialNumber, size%Hard Drive
 %WMIC:Attrib=cpu list brief%Cpu
 %WMIC:Attrib=MemoryChip get BankLabel, Capacity, MemoryType, TypeDetail, Speed%Memory
 %WMIC:Attrib=baseboard get product,Manufacturer,version,serialnumber%BaseBoard
Type "%~n0_outfile.txt"
Endlocal & Endlocal
2
On

that's an interesting question. I didn't know about many of the pc specs commands, but I do know how to save the output to a file. You'll need to append >> OUTPUT.txt to each line of your code.

I've done that for you. Here's the code!

@echo off
echo Checking your system info, Please wait... >> OUTPUT.txt
ipconfig | find /i "IPv4" >> OUTPUT.txt
systeminfo | findstr /c:"Host Name" >> OUTPUT.txt
systeminfo | findstr /c:"OS Name" >> OUTPUT.txt
systeminfo | findstr /c:"System type" >> OUTPUT.txt
systeminfo | findstr /c:"Domain" >> OUTPUT.txt
systeminfo | findstr /c:"OS Version" >> OUTPUT.txt
systeminfo | findstr /c:"System Model" >> OUTPUT.txt
systeminfo | findstr /c:"Total Physical Memory" >> OUTPUT.txt
systeminfo | findstr /c:"System Manufacturer" >> OUTPUT.txt

echo. >> OUTPUT.txt
echo Service Tag: >> OUTPUT.txt
wmic bios get serialnumber >> OUTPUT.txt

echo. >> OUTPUT.txt
echo Hard Drive Space: >> OUTPUT.txt
wmic diskdrive get Name, Manufacturer, Model, InterfaceType, MediaType, SerialNumber, size >> OUTPUT.txt

echo. >> OUTPUT.txt
echo CPU: >> OUTPUT.txt
wmic cpu list brief >> OUTPUT.txt

echo. >> OUTPUT.txt
echo Memory: >> OUTPUT.txt
wmic MemoryChip get BankLabel, Capacity, MemoryType, TypeDetail, Speed >> OUTPUT.txt

echo. >> OUTPUT.txt
echo BaseBoard: >> OUTPUT.txt
wmic baseboard get product,Manufacturer,version,serialnumber >> OUTPUT.txt

pause