Removing Trailing Unit of Measure From Variable ex. "10GB" -> "10"

69 views Asked by At

I am working on a PS script to convert an ExchangeOnline user mailbox to a shared mailbox and would like to implement a safety check. The user mailbox must be under 50GB to be converted to a shared mailbox.

$upn = Read-host -Prompt "Input the UPN of the user you would like to convert. ex. [email protected]
->"
$mailboxsize = get-mailboxstatistics $upn | select TotalItemSize

In this instance

$mailboxsize 

returns:

TotalItemSize
-------------
XX.X GB (XX,XXX,XXX,XXX bytes)

I would like to remove everything after "XX.XX" so that I can use a if/then with a comparitor to either display an error or continue the script. Tried doing some research but not really sure how to word this to get the results I'm after.

This is my first post/question apologies if its in the wrong place/etc. Let me know if I am doing something wrong with formatting or anything else.

Various -arguments Comparing XX.X GB (XX,XXX,XXX,XXX bytes) to XX.X GB (XX,XXX,XXX,XXX bytes)

1

There are 1 answers

1
Dan On

@lit The EXO command works for my application, I guess you can use .Value there but not with the Get-Mailboxstatistics cmlet. I was able to test it and it works great!

#Request UPN

$upn = Read-host -Prompt "Input the UPN of the user you would like to convert. ex. [email protected]
->"


#Get mailbox TotalItemSize value

$MailboxSize = [double](Get-EXOMailboxStatistics -Identity $upn).TotalItemSize.Value


#Compare $mailboxsize against 49.99GB

if($MailboxSize -gt 49990000000){

Write-host -ForegroundColor red $upn is over 50 GB and cannot be converted to a shared mailbox.
Read-Host 'Press any key to quit'
Exit
}