0

I am retrieving computer information using the batch script below,

(
    systeminfo | findstr /c:"Host Name" /c:"Domain" /c:"OS Name" /c:"OS Version" /c:"System Manufacturer" /c:"System Model" /c:"System type" /c:"Total Physical Memory" /c:"Available Physical Memory" 

    wmic bios get serialnumber

) > "getPCinfo.txt"

then result on the text file is

Host Name:                 Host
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.16299 N/A Build 16299
System Manufacturer:       Dell Inc.
System Model:              Latitude 7480
BIOS Version:              Dell Inc. 1.7.3, 10/11/2017
Total Physical Memory:     8,077 MB
Available Physical Memory: 2,450 MB
Domain:                    Domain.Domain.Domain.net
S e r i a l N u m b e r     

 3 R K 5 M H 2               

May I know how can I format the Serial Number into the same format as previous info as something like :-

S e r i a l N u m b e r :   3 R K 5 M H 2  

4 Answers 4

2

I don't like overly long lines in scripts - you loose overview too fast.
This batch uses findstr's default RegEx mode, anchors at line begin with /B
and substitutes the spaces in the search strings with a dot.

:: Q:\Test\2018\06\22\Get-PCInfo.cmd
@Echo off
FOR /F "tokens=1,2 delims==" %%A IN ('
  wmic bios get serialnumber /value ^|find /I "serialnumber"
') DO For %%C in (%%B) Do Set "BIOS=%%A:              %%C"

Set "Find=Host.Name Domain OS.Name OS.Version System.Manufacturer"
Set "Find=%Find% System.Model System.type Total.Physical.Memory"
Set "Find=%Find% BIOS.Version Available.Physical.Memory"

( systeminfo | findstr /I /B "%Find%"
  Echo=%BIOS%
) >getPCinfo.txt

Sample output:

> type getPCinfo.txt
Host Name:                 HOST
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.16299 N/A Build 16299
System Manufacturer:       System manufacturer
System Model:              System Product Name
System Type:               x64-based PC
BIOS Version:              American Megatrends Inc. 1408   , 09/21/2010
Total Physical Memory:     24.566 MB
Available Physical Memory: 14.753 MB
Domain:                    Doamin
SerialNumber:              Number
Sign up to request clarification or add additional context in comments.

Comments

1

This should work for you.

@echo off

systeminfo | findstr /c:"Host Name" /c:"Domain" /c:"OS Name" /c:"OS Version" /c:"System Manufacturer" /c:"System Model" /c:"System type" /c:"Total Physical Memory" /c:"Available Physical Memory">"getPCinfo.txt"

FOR /F "tokens=1,2 delims==" %%G IN ('wmic bios get serialnumber /value ^|find /I "serialnumber"') DO >>"getPCinfo.txt" echo %%G :   %%H

Comments

1

This is a character encoding issue: systeminfo returns ASCII/ANSI text, but wmic returns Unicode text.

Squashman already showed a way to convert the wmic output to ASCII/ANSI text in his answer, although I would write it a bit differently in order to avoid conversion artefacts like orphaned carriage-return (CR) characters:

systeminfo | findstr /c:"Host Name" /c:"Domain" /c:"OS Name" /c:"OS Version" /c:"System Manufacturer" /c:"System Model" /c:"System type" /c:"Total Physical Memory" /c:"Available Physical Memory" > "getPCInfo.txt"
for /F "delims=" %%H in ('wmic BIOS get SerialNumber /VALUE') do for /F "tokens=1* delims==" %%I in ("%%H") do >> "getPCInfo.txt" echo %%I:              %%J

Anyway, here is another method using a temporary file:

systeminfo | findstr /c:"Host Name" /c:"Domain" /c:"OS Name" /c:"OS Version" /c:"System Manufacturer" /c:"System Model" /c:"System type" /c:"Total Physical Memory" /c:"Available Physical Memory" > "getPCInfo.txt"
wmic bios get serialnumber /VALUE > "getPCInfo.tmp"
type "getPCInfo.tmp" >> "getPCInfo.txt"
del "getPCInfo.tmp"

This works only if the hosting cmd instance is not run in Unicode mode (see its /U option), but the default is ASCII/ANSI (/A) anyway.

Comments

1

Here's an untested PowerShell version, only because of how long systeminfo takes:

PCInfo.ps1

$Properties = @{  
  Host_Name = (GWMI Win32_OperatingSystem).CSName
  OS_Name = (GWMI Win32_OperatingSystem).Caption
  OS_Version = GWMI Win32_OperatingSystem | % {$_.Version+' build '+$_.BuildNumber}
  System_Manufacturer = (GWMI Win32_ComputerSystem).Manufacturer
  System_Model = (GWMI Win32_Computersystem).Model
  BIOS_Version = (GWMI Win32_BIOS).SMBIOSBIOSVersion
  Total_Physical_Memory = GWMI Win32_PhysicalMemory | Measure Capacity -Sum | % {[String]$([Math]::Round(($_.Sum / 1MB),0))+' MB'}
  Available_Physical_Memory = GWMI Win32_OperatingSystem | % {[String]$([Math]::Round(($_.FreePhysicalMemory * 1KB / 1MB),0))+' MB'}
  Domain = GWMI Win32_Computersystem | % {$_.DNSHostName +'.'+$_.Domain}
  Serial_Number = (GWMI Win32_BIOS).SerialNumber}
$ColumnWidth = ($Properties.Keys | Measure -Max Length).Maximum
$Properties.GetEnumerator() | Sort Name| % {"{0,-$ColumnWidth}: {1}" -F $_.Key, $_.Value}

To run it, change the paths as necessary and enter the following at the Command Prompt:

PowerShell -NoP -ExecutionPolicy RemoteSigned -File "C:\Users\YHTAN\Desktop\PCInfo.ps1">"C:\Users\YHTAN\Desktop\PCInfo.txt"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.