Batch - WMIC Command output multiple lines add string (Computer Name)
<p>I am trying to make a batch script which will output as follows for fixed-disk:</p>

<p>Computer Name, Drive Letter, Free Disk Space</p>

<p>the output can be one line in case there is only one drive or multiple-lines if there are more than one drive</p>

<p>now with following command, i am getting the output for a computer, but this does not give the computer name. I need to include computer name because i will run it against multiple computers by a script using for loop.</p>

<p>wmic /node:"%COMPUTERNAME%" LogicalDisk Where DriveType="3" Get DeviceID,FreeSpace</p>

<p>using batch script, i can output computer name, but it only appears above the disk-space lines</p>

<pre><code>echo off
for /f %%i in (computers.txt) do (
echo %%i &gt;&gt;outputfile.txt
wmic /node:"%%i" LogicalDisk Where DriveType="3" Get DeviceID,FreeSpace' &gt;&gt;outputfile.txt
)
</code></pre>

<p>if the computer name is "COMPUTER1" and has 3 drives, this is coming as</p>

<pre><code>COMPUTER1
DeviceID  FreeSpace
C:        &lt;free space bytes&gt;
D:        &lt;free space bytes&gt;
E:        &lt;free space bytes&gt;
</code></pre>

<p>what i want is:</p>

<pre><code>ComputerName DeviceID FreeSpace
COMPUTER1    C:       &lt;free space bytes&gt;
COMPUTER1    D:       &lt;free space bytes&gt;
COMPUTER1    E:       &lt;free space bytes&gt;
</code></pre>

<p>event the column header can be excluded.</p>

<p>i believe this can be done by for loop, but not sure how. anyone can advise, will be appreciated. thanks.</p>