-1

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
Compo
  • 36,585
  • 5
  • 27
  • 39
  • 2
    I would strongly advise you not to run a very, very, slow running utility like `systeminfo.exe`, eight times in succession. Did you not consider running it once with eight different `findstr.exe` search patterns? `Out-File -FilePath` is PowerShell , syntax, which works in a `.ps1` script, not a `.cmd` or `.bat` script. You've used the [[tag:batch-file]] tag, are you sure you're wanting a batch file solution? or do you want a PowerShell solution? – Compo Oct 01 '20 at 13:23
  • I am not familiar with this area, but I came in a situation where I need to get the said computer specs of around 190 pc station. so i need something similar to this that i can give to each pc user to run and sent me back the result in text/excel. but this is the most i could get – Chris Taliana Oct 01 '20 at 14:28
  • I'm just telling you not to do it like that Chris. If you want to see what happens, please run your script as is, and tell us how long it taks to complete! Also you will experience another issue in any output file, because the WMI output will be encoded differently and your resulting `.txt` file will have mixed encodings, which will likely spoil the output! – Compo Oct 01 '20 at 14:30
  • yeah, in fact, the final result is not the desired one. I was told to do a for loop, but coding is not my sector and could not get a working script rather than this :( – Chris Taliana Oct 01 '20 at 14:54
  • There are literally hundreds of examples of Windows NT batch, Windows CMD, WSH, and PowerShell, scripts available all over the web, which perform inventory type outputs. Have you considered taking a look at some, and adapting them to your needs? – Compo Oct 01 '20 at 14:58

2 Answers2

0

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
T3RR0R
  • 2,747
  • 3
  • 10
  • 25
  • With regards to the wmic output, nested for loops are one method used to strip errant carriage returns from the output See this [question and it's answers](https://stackoverflow.com/questions/63153754/wmic-output-to-file-without-addtional-line-issue) for more. – T3RR0R Oct 01 '20 at 15:44
-1

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
Benjamin2002
  • 311
  • 1
  • 4
  • 13
  • I did something similar but the print out is not coming clear the part of the wmic. but thanks for the feedback – Chris Taliana Oct 01 '20 at 14:29
  • I would advise you never to use that type of syntax when outputting to one file. In order to do it like that, `output.txt` will need to be opened, written to, then closed, for each and every command line. That is a lot of wasted resources. – Compo Oct 01 '20 at 14:33