0

When I run this command

Get-FsrmQuota -path "F:\prod\..." | Select Path, @{ Name="Usage_GB";Expression={$([math]::Round(($_.Usage / 1GB),2))}}, @{ Name="Size_GB";Expression={$([math]::Round(($_.S
ize / 1GB),2))}} | Sort-Object Path

I get the output below

Path               Usage_GB Size_GB
----              -------- -------
F:\prod\folderA    15.21     500
F:\prod\folderB    86.85     110
F:\prod\folderC        0     0.1
F:\prod\folderD     0.52    0.68
F:\prod\folderE      0.1     0.2

I would like to add 2 new lines at the end, one for “total usage” (sum of all values in the Usage_GB column) and the other “total Size” (sum of all values in the Size_GB Column, but I don’t know how to sum “usage GB” and “size GB”. How can i do it?

Thanks in advance

xabidh
  • 1
  • 1
  • if all you want is to display that info, then you can likely capture the output of `Out-String` and add a new set of lines to that. in any case, you will need to build the output yourself since PoSh has no such built in layout for that data. – Lee_Dailey Apr 16 '20 at 14:52
  • I would just create a new object and append it to your output: `$output +[pscustomobject]@{'Path'='Total';'Usage_GB'=($output.Usage_GB | measure -Sum).Sum;'Size_GB'=($output.Size_GB | Measure -Sum).Sum}`. It may look weird, but it'll be way easier to manipulate in PowerShell. – AdminOfThings Apr 16 '20 at 15:13
  • @AdminOfThings I tried but it doesn't sum, it shows 0 and 0 values – xabidh Apr 20 '20 at 07:00

2 Answers2

0

You could add an extra statement to each expression to keep a rolling total, then output an object with those after sorting:

$TotalUsage = 0
$TotalSize = 0
@(
  Get-FsrmQuota -path "F:\prod\..." | Select Path, @{ Name="Usage_GB";Expression={$([math]::Round(($_.Usage / 1GB),2)); $TotalUsage += $_.Usage}}, @{ Name="Size_GB";Expression={$([math]::Round(($_.Size / 1GB),2)); $TotalSize += $_.Size}} | Sort-Object Path
  [pscustomobject]@{ Path = 'Total'; Usage_GB = [math]::Round(($TotalUsage / 1GB), 2); Size_GB = [math]::Round(($TotalSize / 1GB), 2) }
)
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
0

First of all thanks for your reply @Mathias R. Jessen

I checked it but it looks like it does not sum. I checked and $TotalUsage and $TotalSize is 0

Path                                 Usage_GB Size_GB
----                                 -------- -------
F:\prod\folderA                      15.22     500
F:\prod\folderB                      86.85     110
F:\prod\folderC                          0     0.1
F:\prod\folderD                       0.52    0.68
F:\prod\folderE                        0.1     0.2
Total                                    0       0

xabidh
  • 1
  • 1