title: Batch file help - adding output from command to csv file
body: <p>I currently have a batch file that reads a list of computer names and pings each of these and outputs the ones that reply to a csv file with the computer name and ip address.</p>
  
  <p>I now need to edit this to also find out the user of the machine. I need to contact users which are online to arrange some work done to their computer. Their can be over a hundred machines in the batch file so to manually find out each user takes time. Is there a way to do this?</p>
  
  <pre><code>`IF EXIST C:\test\new.csv (del C:\test\new.csv)
   IF EXIST C:\test\final.csv (del C:\test\final.csv)
   set ComputerList=C:\test\ClientList.txt
   Echo Computer Name,IP Address&gt;Final.csv
   setlocal enabledelayedexpansion
   echo please wait...
   for /f "usebackq tokens=*" %%A in ("%ComputerList%") do (
   for /f "tokens=3" %%B in ('ping -n 1 -l 1 %%A ^|findstr Reply') do (
   set IPadd=%%B
   echo %%A,!IPadd:~0,-1!&gt;&gt;final.csv
   )
   )
   findstr /V "IPAddress" final.csv &gt;&gt; C:\test\new.csv
   echo identified machines for Install
   start excel C:\test\new.csv
   echo opened csv file`
  </code></pre>
  
  <p>The command I want to use to get the username is:</p>
  
  <pre><code> `wmic.exe /NODE: %%A COMPUTERSYSTEM GET USERNAME`
  </code></pre>
  
  <p>Thanks
  Mark</p>