• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 54
  • Last Modified:

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

0
swan_solutions
Asked:
swan_solutions
  • 2
1 Solution
 
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
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
 
swan_solutionsAuthor Commented:
Excellent! Thank you Jose
0
 
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now