Q:

Creating Comma Separated Values in Batch Scripting

I have written a piece of code in Batch script which is somewhat like :
( 
    wmic.exe /node:x.x.x.x computersystem get name
    wmic.exe /node:x.x.x.x computersystem get domain 
    wmic.exe /node:x.x.x.x computersystem get manufacturer 
    wmic.exe /node:x.x.x.x computersystem get model 
    wmic.exe /node:x.x.x.x computersystem get username 
    wmic.exe /node:x.x.x.x computersystem get systemtype
) >> file.txt

The contents of file.txt are :
ABC123  
xyz.com  
Hewlett-Packard  
HP xw4400 Workstation  
ABC123\Administrator  
x64-based PC 

I want above information to be stored in CSV format as follows :
ABC123 , xyz.com , Hewlett-Packard , HP xw4400 Workstation , ABC123\Administrator , x64-based PC 

How can this be achieved?

A:

@echo off
for /f "skip=2 delims=" %%a in (
    'wmic /node:localhost computersystem get name^,domain^,manufacturer^,model^,username^,systemtype /format:csv'
) do (
    for /f "tokens=2-7 delims=," %%b in ("%%a") do (
        echo(%%e , %%b , %%c , %%d , %%g , %%f
    )
) >> file.txt

In case you doub why the two for commands, the output of the WMIC contains an aditional carriage return character that has to be removed.

