Formatting mailbox size results in PowerShell

We are currently working on a PowerShell script to determine what the warning limits are for mailboxes in 365 and to change them, as requested by our client.

We have the script working and it gives us the results we need but what we would like to do is remove the bytes size which is shown alongside the results '61.9 MB (64,902,919 bytes)'

Is it possible to remove the bytes so it only shows 61.9Mb

Any comments or assistance would be greatly appreciated.

#ADD THE 365 ADMIN USER DETAILS
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

#VIEW INFORMATION OF ALL MAILBOXES
Get-Mailbox | Select-Object Displayname,identity,PrimarySmtpAddress,@{Name='TotalItemSize (GB)'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).TotalItemSize))}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},IssueWarningQuota, ProhibitSendQuota | Format-Table

#PUSH ANY KEY TO CONTINUE - LETTING THE TECHNICIAN USING THE SCRIPT TO REVIEW THE RESULTS
Read-Host -Prompt "Press Enter to continue"

#CREATE THE MINIMISE OBJECT
$shell = New-Object -ComObject "Shell.Application" 
$shell.minimizeall() #Minimize all windows

#TEXT BOX NEEDING THE EMAIL ADDRESS TO BE CHANGED
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$User = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the email address to change', 'Email alert quote change') 

#TEXTBOX FOR THE SIZES
$VARIssueWarningQuota = [Microsoft.VisualBasic.Interaction]::InputBox('Issue Warning Quota change. Enter value and size type, e.g. 10gb for 10 GigaBytes', 'Issue Warning Quota') 

#MAXIMISE ALL WINDOWS
$shell = New-Object -ComObject "Shell.Application"
$shell.undominimizeall() 

#CHANGE QUOTAS USING THE VARIABLED ENTERED IN LINE 21
Set-Mailbox $user -id -IssueWarningQuota $VARIssueWarningQuota

#GET UPDATED QUOTE INFORMATION
Get-Mailbox $User | Select-Object Displayname,Database,@{Name='TotalItemSize'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).TotalItemSize))}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},IssueWarningQuota, ProhibitSendQuota

Open in new window

swan_solutionsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEOCommented:
The corrected script would be:

#ADD THE 365 ADMIN USER DETAILS
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

#VIEW INFORMATION OF ALL MAILBOXES

Get-Mailbox  -ResultSize unlimited| Select-Object Displayname,identity,PrimarySmtpAddress,@{Name='TotalItemSize (GB)'; Expression={[math]::Round((((Get-MailboxStatistics -identity $_.identity).TotalItemSize.ToString()).Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},@{name="IssueWarningQuota (GB)";expression={ ($_.IssueWarningQuota.ToString()).Split("(")[0]}},@{name="ProhibitSendQuota (GB)";expression={($_.ProhibitSendQuota.ToString()).Split("(")[0]}}  | Format-Table



#PUSH ANY KEY TO CONTINUE - LETTING THE TECHNICIAN USING THE SCRIPT TO REVIEW THE RESULTS
Read-Host -Prompt "Press Enter to continue"

#CREATE THE MINIMISE OBJECT
$shell = New-Object -ComObject "Shell.Application" 
$shell.minimizeall() #Minimize all windows

#TEXT BOX NEEDING THE EMAIL ADDRESS TO BE CHANGED
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$User = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the email address to change', 'Email alert quote change') 

#TEXTBOX FOR THE SIZES
$VARIssueWarningQuota = [Microsoft.VisualBasic.Interaction]::InputBox('Issue Warning Quota change. Enter value and size type, e.g. 10gb for 10 GigaBytes', 'Issue Warning Quota') 

#MAXIMISE ALL WINDOWS
$shell = New-Object -ComObject "Shell.Application"
$shell.undominimizeall() 

#CHANGE QUOTAS USING THE VARIABLED ENTERED IN LINE 21
Set-Mailbox $user -id -IssueWarningQuota $VARIssueWarningQuota

#GET UPDATED QUOTE INFORMATION
#Get-Mailbox |                      Select-Object Displayname,identity,PrimarySmtpAddress,@{Name='TotalItemSize (GB)'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).TotalItemSize))}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},IssueWarningQuota, ProhibitSendQuota | Format-Table
Get-Mailbox  -ResultSize unlimited| Select-Object Displayname,identity,PrimarySmtpAddress,@{Name='TotalItemSize (GB)'; Expression={[math]::Round((((Get-MailboxStatistics -identity $_.identity).TotalItemSize.ToString()).Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},@{name="IssueWarningQuota (GB)";expression={ ($_.IssueWarningQuota.ToString()).Split("(")[0]}},@{name="ProhibitSendQuota (GB)";expression={($_.ProhibitSendQuota.ToString()).Split("(")[0]}}  | Format-Table

Open in new window


res.png
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
swan_solutionsAuthor Commented:
Excellent! Thank you Jose
0
Jose Gabriel Ortega CastroCEOCommented:
And if you want the totalitemsSize in mb would be like this:

#ADD THE 365 ADMIN USER DETAILS
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

#VIEW INFORMATION OF ALL MAILBOXES

Get-Mailbox  -ResultSize unlimited| Select-Object Displayname,identity,PrimarySmtpAddress,@{Name='TotalItemSize (MB)'; Expression={[math]::Round((((Get-MailboxStatistics -identity $_.identity).TotalItemSize.ToString()).Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},@{name="IssueWarningQuota (GB)";expression={ ($_.IssueWarningQuota.ToString()).Split("(")[0]}},@{name="ProhibitSendQuota (GB)";expression={($_.ProhibitSendQuota.ToString()).Split("(")[0]}}  | Format-Table



#PUSH ANY KEY TO CONTINUE - LETTING THE TECHNICIAN USING THE SCRIPT TO REVIEW THE RESULTS
Read-Host -Prompt "Press Enter to continue"

#CREATE THE MINIMISE OBJECT
$shell = New-Object -ComObject "Shell.Application" 
$shell.minimizeall() #Minimize all windows

#TEXT BOX NEEDING THE EMAIL ADDRESS TO BE CHANGED
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$User = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the email address to change', 'Email alert quote change') 

#TEXTBOX FOR THE SIZES
$VARIssueWarningQuota = [Microsoft.VisualBasic.Interaction]::InputBox('Issue Warning Quota change. Enter value and size type, e.g. 10gb for 10 GigaBytes', 'Issue Warning Quota') 

#MAXIMISE ALL WINDOWS
$shell = New-Object -ComObject "Shell.Application"
$shell.undominimizeall() 

#CHANGE QUOTAS USING THE VARIABLED ENTERED IN LINE 21
Set-Mailbox $user -id -IssueWarningQuota $VARIssueWarningQuota

#GET UPDATED QUOTE INFORMATION
#Get-Mailbox |                      Select-Object Displayname,identity,PrimarySmtpAddress,@{Name='TotalItemSize (GB)'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).TotalItemSize))}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},IssueWarningQuota, ProhibitSendQuota | Format-Table
Get-Mailbox  -ResultSize unlimited| Select-Object Displayname,identity,PrimarySmtpAddress,@{Name='TotalItemSize (MB)'; Expression={[math]::Round((((Get-MailboxStatistics -identity $_.identity).TotalItemSize.ToString()).Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},@{name="IssueWarningQuota (GB)";expression={ ($_.IssueWarningQuota.ToString()).Split("(")[0]}},@{name="ProhibitSendQuota (GB)";expression={($_.ProhibitSendQuota.ToString()).Split("(")[0]}}  | Format-Table

Open in new window

0
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Jose [MCSE] Ortega C (https:#a42384597)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Pber
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.