Customize output Get-fsrmQuota report

885 Views Asked by At

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

2

There are 2 best solutions below

0
Mathias R. Jessen On

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) }
)
0
xabidh On

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