-1

I am currently using this quick batch file to get info that I need from a variety of computers. My problem is that it creates the CSV file, but it is all one column. I am planning to use python to manipulate the data, but it is difficult to do so if it is all one column.

@echo off

(systeminfo | findstr /c:"Host Name"
systeminfo | findstr /c:"OS Name"
systeminfo | findstr /c:"System Model"
systeminfo | findstr /c:"System type"
systeminfo | findstr /c:"Total Physical Memory"
ipconfig | findstr IPv4
wmic diskdrive get size
wmic bios get serialnumber
wmic cpu get name)>>in.csv
3
  • 4
    1. The output is not really a CSV file. 2. systeminfo needs quite some time, so calling it multiple times could be avoided by writing its output to a temporary file once and then let findstr gather the required information from there. 3. systeminfo returns ASCII/ANSI text, while wmic returns Unicode text; mixing them is a quite bad idea. 4. You did not specify the desired output format, neither did you provide a minimal reproducible example of your own attempt to implement it; please take the tour and learn to How to Ask here on this site! Commented Mar 20, 2019 at 20:45
  • 1
    ad 2. As an alternative to a temporary file, simply use multiple search strings, like systeminfo | findstr /C:"Host Name" /C:"OS Name" ..., etc. ad 3. take a look at this answer or this one... Commented Mar 20, 2019 at 21:37
  • 1
    Wmic /format /? wmic /append /? Commented Mar 20, 2019 at 22:15

1 Answer 1

1

All output, single line, comma delimited, and sub-delimits on both IP address and disk drive, since there are multiple of those. Sub-delimit is a semi-colon.

Output:

MyBox,36527083,Packard Bell,3-2,Microsoft Windows 10,x64-based PC,17087881216,192.168.121.1;192.168.3.1;10.11.18.112,Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz,2000396321280;63992678400;4000784417280;512105932800;1500299297280

Cmd:

@echo off
setlocal EnableDelayedExpansion

set "zManufacturer="
set "zHostName="
set "zOsName="
set "zSystemModel="
set "zSystemType="
set "zTotalPhysicalMemory="
set "zIpAddresses="
set "zHddSizes="
set "zCpuName="
set "zBiosSerial="

for /f "skip=1 tokens=1-6 delims=," %%A in ('wmic computersystem get Manufacturer^,Model^,TotalPhysicalMemory^,SystemType^,Workgroup /format:csv ^| findstr ","') do (
    set "zHostName=%%A"
    set "zManufacturer=%%B"
    set "zSystemModel=%%C"
    set "zSystemType=%%D"
    set "zTotalPhysicalMemory=%%E"
)

for /f "tokens=2 delims=:" %%A in ('ipconfig ^| findstr /i ipv4') do set "zIpAddresses=!zIpAddresses!%%A"
set "zIpAddresses=!zIpAddresses:~1!"
set "zIpAddresses=!zIpAddresses: =;!"

for /f "tokens=1 delims=|" %%A in ('wmic os get name ^|findstr "|"') do set "zOsName=%%A"

for /f "tokens=2 delims=," %%A in ('wmic bios get serialnumber^,version /format:csv') do set "zBiosSerial=%%A"

for /f "tokens=2 delims=," %%A in ('wmic cpu get name^,version /format:csv') do set "zCpuName=%%A"

for /f "skip=1 tokens=2 delims=," %%A in ('wmic diskdrive get size^,TracksPerCylinder /format:csv ^|findstr /v /r "^$"') do set "zHddSizes=!zHddSizes!;%%A"
set "zHddSizes=!zHddSizes:~1!"

echo !zHostName!,!zBiosSerial!,!zManufacturer!,!zSystemModel!,!zOsName!,!zSystemType!,!zTotalPhysicalMemory!,!zIpAddresses!,!zCpuName!,!zHddSizes!
Sign up to request clarification or add additional context in comments.

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.