title: Unable to get batch script to display IP address, Ping status, and hostname into a single 3 column .csv
body: <p>I'm trying to ping against a list of websites and get the following output in a .csv, Hostname, success of ping, IP address. So the output might look like this:</p>
  
  <p>Google.com, Successful (or failure), 123.456.789.012 (if failure N/A)</p>
  
  <p>I have two scripts that can do these things seperatley, but can't seem to get them to work together. </p>
  
  <p>Gets IP addresses:</p>
  
  <pre><code>@echo off
  set ComputerList=C:\Scripts\pinglist.txt
  Echo Computername,IP Address&gt;&gt;pingresult.csv
  setlocal enabledelayedexpansion
  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;pingresult.csv
  ))*
  </code></pre>
  
  <p>Gets hostname and ping status:</p>
  
  <pre><code>REM Set the "PingList" variable to the location of the text file you want to ping against
  set PingList=C:\Scripts\pinglist.txt
  REM Set the "Results" variable to the location where you want to pipe your output
  set Results=C:\Scripts\pingresult.csv
  echo COMPUTERNAME, STATUS &gt;&gt; %Results%
  REM failed pings appened to file
  for /f "delims=" %%a in (%PingList%) do ping -n 1 %%a &gt;nul &amp;&amp; (echo %%a ok) || (echo %%a, failure ) &gt;&gt; %Results%
  REM successful pings appened to file
  for /f "delims=" %%a in (%PingList%) do ping -n 1 %%a &gt;nul &amp;&amp; (echo %%a, success ) &gt;&gt; %Results% || (echo %%a failed to respond)
  </code></pre>