Let’s say we have to display SharePoint site collection size using PowerShell. We can easily use Client Object Model and PowerShell to accomplish that. Let’s do it step by step:
PS > $spsite = Get-SPSite “http://sharepoint:100” PS > $spsite.Usage |
It will display data like this:
Hmmm, interesting. It shows the size and also some other user information like visits and bandwidth. But, we just care for the size. So let’s modify the code:
PS > $spsite.Usage.Size |
Now the output looks like this:
3514033
Ok, we have the size but it’s in bytes. Let’s convert that to MB.
PS > $spsite.Usage.Size / 1000000 or alternatively we can use this code: PS > $spsite | select @{Name=”Size”; Expression={$_.Usage.Size / 1000000 }} |
The output looks like this:
3.514033
Still doesn’t look good. Now we can use the expression formatting to make it human friendly:
PS > $spsite | select @{Name="Size"; Expression={"{0:N2} MB" -f ($_.Usage.Storage/1000000)}} |
Bingo, now it shows up as:
3.51 MB
0:N2 is the standard .NET based format. 0 would means the argument position and N2 means number format with 2 decimal places. –f is used for pass the argument to the format.