none
Formatting output RRS feed

  • Question

  • Hi Scripting Guy(s),

    I'm trying to format the output of a script that checks some servers for their available disk space.  This is what I have so far that works:

    $srvrs = (Get-Content -Path C:\Users\foo\ps\srvrs.txt)
    foreach ( $i in $srvrs )
    {
    Get-WmiObject -class win32_logicaldisk –computer $i
    }

    which produces the left-aligned output:

    ------ / snip / ----------

    DeviceID     : I:
    DriveType    : 3
    ProviderName : 
    FreeSpace    : 48159457280
    Size         : 53550710784
    VolumeName   : TEMPDBDATA

    ------/ snip / ----------

    What I would like to get is the servername with the different drives listed across the page instead of just left aligned.  I've tried the following code appended to the above code:

    Format-Table $i, DeviceId, MediaType, Size %{ $i.DeviceID; $i.VolumeName; $i.FreeSpace/1GB }, -wrap

    And it will still generate the left aligned output and the following error:

    ---------- / error / ----------------

    Format-Table : A positional parameter cannot be found that accepts argument '%'.
    At line:8 char:1
    + Format-Table $i, DeviceId, MediaType, Size %{ $i.DeviceID; $i.VolumeName; $i.Fre ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Format-Table], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.FormatTableCommand

    ---------- / error / --------------

    Can anyone help identify what I'm missing on the formatting command?  I checked the man page for format-table and some google references, but still haven't found joy.


    • Edited by bp7825478606 Thursday, September 14, 2017 3:15 PM
    Thursday, September 14, 2017 3:13 PM

Answers