powershell - Diskspace info from a remote server, multiple drives in one string no CR LF -


i want remote server's disk drive , current diskspace info (for drivetype 3, no cd's or removables) in single string inclusion in server inventory spreadsheet (a status snapshot).

the following code:

get-wmiobject win32_volume -computer <servername> -filter "drivetype='3'"|   select driveletter,          @{name="capacity (gb)";expression={[math]::round(($_.capacity/1gb),2)}},          @{name="freespace (gb)";expression={[math]::round(($_.freespace/1gb),2)}}  

gives me output this:

driveletter   capacity (gb)            freespace (gb) -----------   -------------            -------------- c:            50                       38.89 e:            309.99                   26.28 p:            10                        5.95

i prefer this, on 1 line can stuff in spreadsheet:

c:\38.89/50 e:\26.28\309.99 p:\5.95\10

but i'm unsure of how on single line.

$result = '' get-wmiobject win32_volume -computer $env:computername -filter "drivetype='3'" | % {     $result += '{0}\{1}\{2} ' -f $_.driveletter, [math]::round(($_.freespace/1gb),2), [math]::round(($_.capacity/1gb),2) } $result.trim() 

recommended alternative:

(get-wmiobject win32_volume -computer $env:computername -filter "drivetype='3'" | % {'{0}\{1}\{2}' -f $_.driveletter, [math]::round(($_.freespace/1gb),2), [math]::round(($_.capacity/1gb),2)})-join' ' 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -