Avatar of K B
K B
Flag for United States of America asked on

PowerShell: Adding ToGB to a script

I cannot seem to convert the SUM to GBs... where would that go?

$report = Get-MoveRequest -ResultSize 10| Get-MoveRequestStatistics | 
    Select-Object -Property @{n = "DatebaseName"; e = {$_.targetdatabase.name}}, totalmailboxsize
$report | Group-Object -Property DatebaseName | Select-Object -Property @{n = "DatebaseName"; e = {$_.Name}}, @{n = "Sum"; e = {($PSItem.group | Measure-Object -Property totalmailboxsize -sum).Sum}} |
    Sort-Object -Property Sum -Descending |
    Out-GridView -Title "Size Per Database"

Open in new window



Thank you
Powershell.NET ProgrammingExchangeMicrosoft 365Active Directory

Avatar of undefined
Last Comment
footech

8/22/2022 - Mon
Vasil Michev (MVP)

The ToGB method is only available for some types. You can simply do some divisions (/1024) to convert the integer you are getting from Sum to KB/MB/etc.
K B

ASKER
Thank you Vasil.

I think I tried with /1GB and the numbers were off by a bunch.  I will give /1024 a try.
K B

ASKER
$report = Get-MoveRequest -ResultSize Unlimited| Get-MoveRequestStatistics | 
    Select-Object -Property @{n = "DatebaseName"; e = {$_.targetdatabase.name}}, totalmailboxsize
$report | Group-Object -Property DatebaseName | Select-Object -Property @{n = "DatebaseName"; e = {$_.Name}}, @{n = "Sum"; e = {(($PSItem.group | Measure-Object -Property totalmailboxsize -sum).Sum)/1GB}} |
    Sort-Object -Property Sum -Descending |
    Out-GridView -Title "Size Per Database"

Open in new window


I believe this works but needs to be rounded to the nearest whole number
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.