Hello, I am using the following command to retrieve stats from FSRM but cannot figure out how to return both Size and Usage in GB. I don’t understand what the @ is doing here… building an array ? Help much appreciated.
Get-FsrmQuota | Format-Table Path, Size, @{Label=“Usage GB”; Expression={$($_.size/1GB) -as [int] }} -auto
This commend displays only the Usage in GB, size is still in bytes.
The posted code is using a Calculated Expression\Property. Rather then running a for loop to create a new custom object, you can leverage calculated expressions to reformat or really do anything inside of a column. Basically, the defined expression is code, so your code would look something like:
$(19899999947 / 1GB) -as [int]
The $() wrapper is more a order of operations to ensure the math is completed before using -as [int] to do rounding for you. The 1gb is a multiplier so that you don’t need to do exponential math for 1024 times 3,4,5 etc.
#Create a test object
$test = [pscustomobject]@{Path='d:\www\example.com';Size=3758096384}
#You create another column called SizeGB and divide the value of Size by 1gb
$test | Select-Object Path, Size, @{Name='SizeGB';Expression={$_.Size / 1gb}}
#You can add the current date using nothing in the current test object. Notice it is using Label not Name, same difference, potato potater
$test | Select-Object Path, Size, @{Name='SizeGB';Expression={$_.Size / 1gb}}, @{Label='CurrentDate';Expression={(Get-Date)}}
#You can also change the Size column to do the math
$test | Select-Object Path, @{Name='Size';Expression={$_.Size / 1gb}}
Output:
PS C:\Users\Rob> $test | Select-Object Path, Size, @{Name='SizeGB';Expression={$_.Size / 1gb}}
Path Size SizeGB
---- ---- ------
d:\www\example.com 3758096384 3.5
PS C:\Users\Rob> $test | Select-Object Path, Size, @{Name='SizeGB';Expression={$_.Size / 1gb}}, @{Label='CurrentDate';Expression={(Get-Date)}}
Path Size SizeGB CurrentDate
---- ---- ------ -----------
d:\www\example.com 3758096384 3.5 10/8/2018 9:47:49 AM
PS C:\Users\Rob> $test | Select-Object Path, @{Name='Size';Expression={$_.Size / 1gb}}
Path Size
---- ----
d:\www\example.com 3.5
You can read more here: Using PowerShell's Calculated Properties -- Microsoft Certified Professional Magazine Online