I'm currently trying to create a disk usage report that receives a list of servers and outputs to a csv file. The report will be run as a daily scheduled task. Currently I'm using WMIC to query all the boxes, which are all W2K/W2K3. I'm not sure if there are other methods that get around the problem I've encountered so please feel free to suggest anything that helps
The problem I have is that WMIC returns disk usage values in bytes, which I'm sure you'll agree is totally useless to any human being with a calculator for a brain. I thought to output first to a temporary csv file then re-read the file with a for /f loop and parse the values with some equations so that excel would display the figures in GB. I came up with the following script, it generates correct values in most places but for some reason drops in carriage returns that break up the equations and send Excel up the wall
Hope someone out there can help. There is a surprisingly limited amount of info on the net regarding equations in batch script
Regards,
Warren
Code: Select all
SET SERVER_LIST=%1
SET OUTPUT_FILE=%2
SET GB_D=0
SET GB_E=0
FOR /F %%A IN (%SERVER_LIST%) DO WMIC /Node:%%A LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size /Format:csv | MORE /E +2 >> tmp-%OUTPUT_FILE%
echo Hostname,Drive,File System,Volume Label,Free Space (GB),Size (GB),Percent Free > %OUTPUT_FILE%
FOR /F "tokens=1,2,3,4,5,6 delims=," %%a IN (tmp-%OUTPUT_FILE%) DO echo %%a,%%b,%%c,%%f,=%%d/1024/1024/1024,=%%e/1024/1024/1024,=%%d/%%e*100 >> %OUTPUT_FILE%
del tmp-%OUTPUT_FILE%