Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>Function RightJustified(ColumnValue, ColumnWidth) RightJustified = Space(ColumnWidth - Len(ColumnValue)) &amp; ColumnValue End Function </code></pre> <p>Usage example:</p> <pre><code>output = output &amp; _ RightJustified(strDiskSize, 15) &amp; _ RightJustified(strUsedSpace, 15) &amp; _ RightJustified(strFreeSpace, 15) &amp; _ RightJustified(pctFreeSpace, 15) &amp; _ vbCrLf </code></pre> <p><strong>EDIT</strong></p> <p>Add the <strong>RightJustified</strong> function to your script.</p> <p>Then, replace this line of your code:</p> <pre><code>txt = txt &amp; objItem.Name &amp; vbtab &amp; vbtab &amp; strDiskSize &amp; vbtab &amp; vbtab &amp; strUsedSpace &amp; vbTab &amp; vbtab &amp; strFreeSpace &amp; vbtab &amp; vbtab &amp; pctFreeSpace &amp; vbcrlf </code></pre> <p>with:</p> <pre><code>txt = txt &amp; objItem.Name &amp; _ RightJustified(strDiskSize, 15) &amp; _ RightJustified(strUsedSpace, 15) &amp; _ RightJustified(strFreeSpace, 15) &amp; _ RightJustified(pctFreeSpace, 15) &amp; _ vbCrLf </code></pre> <hr> <h2><strong>EDIT 2</strong></h2> <p>I added the RightJustified function at the bottom of your script, and then called it within your loop to format the columns. I also used it on the column headers. Below is the script and at the bottom is the output on my machine.</p> <pre><code>Option Explicit const strComputer = "." const strReport = "F:\dba_scripts\diskspace.txt" Dim objWMIService, objItem, colItems Dim strDriveType, strDiskSize, txt Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3") txt = RightJustified("DRIVE", 10) &amp; _ RightJustified("SIZE", 15) &amp; _ RightJustified("USED", 15) &amp; _ RightJustified("FREE", 15) &amp; _ RightJustified("FREE(%)", 15) &amp; _ vbCrLf For Each objItem in colItems DIM pctFreeSpace,strFreeSpace,strusedSpace pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10 strDiskSize = round((objItem.Size /1073741824),1) &amp; " GB" strFreeSpace = round((objItem.FreeSpace /1073741824),1) &amp; " GB" strUsedSpace = round(((objItem.Size-objItem.FreeSpace)/1073741824),1) &amp; " GB" txt = txt &amp; _ RightJustified(objItem.Name, 10) &amp; _ RightJustified(strDiskSize, 15) &amp; _ RightJustified(strUsedSpace, 15) &amp; _ RightJustified(strFreeSpace, 15) &amp; _ RightJustified(pctFreeSpace, 15) &amp; _ vbCrLf Next writeTextFile txt,strReport wscript.echo "Report written to " &amp; strReport &amp; vbcrlf &amp; vbcrlf &amp; txt ' Procedure to write output to a text file Sub writeTextFile(byval txt,byval strTextFilePath) Dim objFSO,objTextFile set objFSO = createobject("Scripting.FileSystemObject") set objTextFile = objFSO.CreateTextFile(strTextFilePath) objTextFile.Write(txt) objTextFile.Close Set objTextFile = nothing End Sub Function RightJustified(ColumnValue, ColumnWidth) RightJustified = Space(ColumnWidth - Len(ColumnValue)) &amp; ColumnValue End Function </code></pre> <p>Output produced:</p> <pre><code> DRIVE SIZE USED FREE FREE(%) C: 48.4 GB 40.6 GB 7.8 GB 16.1 D: 100.6 GB 56.8 GB 43.8 GB 43.5 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload