How to select from Exchange mailboxes of size "greater than" 75Gb

Hello! I need to select all mailboxes larger than 75Gb, using script parameters below, but I can’t get it to select proper size from TotalItemSize using Expression. When I run the script it selects all mailboxes, where first two digits in TotalItemSize are greater that 75, but the rest of size does not count. I get mailboxes of any size, where TotalItemSize starts with a digit above 75. It can be a mailbox of size in 100Mbs or less. Where is mistake in the Expression parameters, I don’t understand. Ask you for help -))

Get-Mailbox -ResultSize 10 -Filter {SamaccountName -notlike “RP-20*” -and CustomAttribute10 -ne $null -and RecipientTypeDetails -ne ‘EquipmentMailbox’} | select PrimarySMTPAddress, ExchangeGUID, CustomAttribute10, LegacyExchangeDN, @{Expression={(Get-MailboxStatistics $.alias).TotalItemSize.tostring().split(" “)[2].replace(”(","").replace(",","")};Label=“TotalItemSize”;} | where {$.TotalItemSize -gt 75161927680}

Welcome to the forum. :wave:t4:

If you run this query directly on your Exchange server you can use something like this:

Where-Object {(Get-MailboxStatistics $_.alias).totalitemsize.value.tobytes() -gt 75GB}

If you use your approach you may cast the result of your string acrobatics to [int64] for the comparison against the value of 75GB. :wink:

and BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

Hello, Olaf, I’m using remote power shell connection via exchange session, not directly on the server. Did you mean that my command will look like this? If I used this correctly, then it does not work. I get mulitple errors. And thank you for hint how to place the code.
@{Expression={(Get-MailboxStatistics $_.alias).TotalItemSize.tostring().split(" ")[2].replace("(","").replace(",","")};Label="TotalItemSize";} | Where-Object {(Get-MailboxStatistics $_.alias).totalitemsize.value.tobytes() -gt 75GB}

No. The code I posted will only work if you run the code directly on the Exchange server. :point_up_2:t4:

If you use a remote shell the needed method will not survive the serialization and de-serialization happening during the remote execution. :wink:

Errors are an important feature of any scripting or programming language. If you get errors you should read and try to understand them. If you don’t understand them you should post them here (properly formatted as code as well, please) along with the code you used.

I meant that you should try to cast the result of your string manipulation to [int64] for the comparison against your limit of 75GB.

Could you please try to properly format your code as code? When you compare the display of the code I posted and the code you posted you can see a difference. Click the link I posted and follow the instructions.

Without having access to an Exchange server at the moment … using your original code … something like this should work:

Get-Mailbox -ResultSize 10 -Filter { SamaccountName -notlike 'RP-20*' -and CustomAttribute10 -ne $null -and RecipientTypeDetails -ne 'EquipmentMailbox' } | 
    Where-Object { [int64]((Get-MailboxStatistics $_.alias).TotalItemSize.value -replace '^.+\(|\s+\w+\)|,') -gt 75GB}

Hello, Olaf, thank you for your help! Second suggestion did not work (or I implemented it with mistake). Here is the code that worked for me. Sorry, I do not understand how to make use of Preformatted text -((

Preformatted text</> @{Expression={((Get-MailboxStatistics $.alias).TotalItemSize.tostring().split(" “)[2].replace(”(","").replace(",","") -as [long])};Label=“TotalItemSize”;},ident* | where {$.TotalItemSize -gt 75161927680}</> Preformatted text

Just click on the link I posted. It’s a animanted GIF. There’s actually no way to missunderstand it. :wink:

OK. If you’re satisfied - that’s all what counts. :+1:t4: :man_shrugging:t4: :wink:

1 Like