Script compression in batch mode for wmic command

I am trying to run a script package to get basic computer information such as CPU, RAM and active network card. Here is my code

@Echo OFF set newline=^& echo. echo Manufacturer Information> test1.txt systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" >>test1.txt echo CPU Information:>> test1.txt wmic cpu get Name /Format:list >> test1.txt echo %newline%Process Information:>> test1.txt wmic computersystem get NumberofProcessors /Format:list >> test1.txt echo %newline%NIC Information:>> test1.txt wmic nicconfig where "IPEnabled=TRUE" get ipaddress, macaddress,defaultipgateway /format:list >>test1.txt 

The result looks like:

Manufacturer Information Host Name: DK-IT OS Name:
Single-language system model Microsoft Windows 8.1:
Inspiron 7537 System Type: x64-based Computer Total Physical Memory: 6.043 MB Processor Information:

  N ame = I ntel ( R ) C ore ( TM ) i 5 - 4 2 0 0 UCPU @ 1 . 6 0 GH z Process Information: N umber O f P rocessors = 1 NIC Information: D efault IPG ateway = { " 1 0 . 5 . 1 . 1 " } IPA ddress = { " 1 0 . 5 . 4 . 5 4 " , " fe 8 0 : : 1 0 eb : 1 d 

2 d: 2 0 8 8: 8 ba 1 "} MACA ddress = 0 C: 8 B: FD: 9 C: 8 0: 4 7

  D efault IPG ateway = IPA ddress = { " 1 9 2 . 1 6 8 . 1 9 9 . 1 " } MACA ddress = 0 0 : 5 0 : 5 6 : 

C 0: 0 0: 0 1

D efault i PG ateway = i PA ddress = {"1 9 2, 1 6 8. 1 9 0. 1", "fe 8 0 :: 6 4 b 2: 2 aa: ef 6 4: fa 9 a"} MACA ddress = 0 0: 5 0: 5 6: C 0: 0 0: 0 8

Can someone help change the appearance of the output of the batch file?

+3
source share
1 answer

Your problem is that SYSTEMINFO produces ANSII output (like most commands), but WMIC produces Unicode output. The two do not mix well.

Below are three solutions that produce ANSII output.

1) Output WMIC to MORE

MORE converts Unicode to ANSII. I also pass this FINDSTR result to eliminate blank lines. The only problem with this solution is that the quirk with conversions causes the WMIC output to have an extra carriage return at the end of each line ( <CR><CR><LF> instead of <CR><LF> )

 @echo OFF >test1.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo CPU Information: wmic cpu get Name /Format:list | more | findstr . wmic computersystem get NumberofProcessors /Format:list | more | findstr . echo( echo NIC Information: wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list | more | findstr . ) 


------------------------------

Other solutions are fully formatted without additional <CR>

2) Write WMIC output to temp file and then TYPE

The temporary file is in Unicode format, and TYPE correctly converts Unicode to ANSII. I am still passing FINDSTR result to eliminate blank lines.

 @echo OFF >test2.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo CPU Information: call :wmic cpu get Name /Format:list call :wmic computersystem get NumberofProcessors /Format:list echo( echo NIC Information: call :wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list ) exit /b :wmic wmic %* >test.tmp type test.tmp | findstr . del test.tmp exit /b 


3) Run WMIC through two FOR / F loops.

The first FOR / F converts the output of WMIC to ANSII, but has the value <CR> at the end of each line. The second FOR / F removes the unwanted trailing <CR> . FOR / F automatically deletes empty lines.

 @echo OFF >test3.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo CPU Information: call :wmic cpu get Name /Format:list call :wmic computersystem get NumberofProcessors /Format:list echo( echo NIC Information: call :wmic nicconfig where IPEnabled=TRUE get ipaddress, macaddress,defaultipgateway /format:list ) exit /b :wmic for /f "delims=" %%A in ('"wmic %*"') do for /f "delims=" %%B in ("%%A") do echo %%B exit /b 
+3
source

All Articles