none
Powershell - MailBox Real dimension RRS feed

  • Question

  • Hi all,
    i need a powershell script for watch the real dimension (allocate dimension on mailbox not only the consume space).

    In another post a a good guy suggest me to use this script for calculate the real dimension of mailbox:


    $AllMailboxes = @()
    $Mailboxes = Get-Mailbox -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime
    foreach ($Mailbox in $Mailboxes){
        $MailboxStats = "" |Select  Nome,Database,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,DimensioneTotale,ElementiCancellati,NumeroMail,StorageLimitStatus,Account,LastLogonTime,SpazioRimanente
        $Stats = Get-MailboxStatistics -Identity $Mailbox.Alias
        $MailboxStats.Nome = $Mailbox.DisplayName
    	$MailboxStats.Account = $Stats.LastLoggedOnUserAccount
        $MailboxStats.Database = $Mailbox.Database
        $MailboxStats.IssueWarningQuota = $Mailbox.IssueWarningQuota
        $MailboxStats.ProhibitSendQuota = $Mailbox.ProhibitSendQuota
        $MailboxStats.ProhibitSendReceiveQuota = $Mailbox.ProhibitSendReceiveQuota
    	$MailboxStats.ElementiCancellati = $Stats.TotalDeletedItemSize
        $MailboxStats.DimensioneTotale = $Stats.TotalItemSize
        $MailboxStats.NumeroMail = $Stats.ItemCount
        $MailboxStats.StorageLimitStatus = $Stats.StorageLimitStatus
    	$MailboxStats.LastLogonTime = $Stats.LastLogonTime
    	try {$MailboxStats.SpazioRimanente = ($Mailbox.ProhibitSendReceiveQuota - $Stats.TotalItemSize)} Catch { "Error on $($MailboxStats.Nome)"}
        $AllMailboxes += $MailboxStats
    }
    #creo csv 
    $AllMailboxes | Export-Csv C:\mailboxInfo.csv -NoTypeInformation -delimiter ';'

    It works but i need to use not for all mailbox, but i need for the mailbox in specific Database.

    How i can use this script for search in a specific DB, like for example CUSTOMER-DB1?

    Regards
    Angelo

    Thursday, December 27, 2018 4:11 PM

Answers

  • Hi Angelo,

    From this information below, we can know, there have two mailboxes have the same Alias:

    Get-MailboxStatistics : The specified mailbox "direzione"  isn't unique

    So, we should modify it as the script below:

    $AllMailboxes = @()
    $Mailboxes = Get-Mailbox -Database "CUSTOMER-DB1" -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Name, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime
    foreach ($Mailbox in $Mailboxes){
        $MailboxStats = "" | Select  Nome,Database,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,DimensioneTotale,ElementiCancellati,NumeroMail,StorageLimitStatus,Account,LastLogonTime,SpazioRimanente
        $Stats = Get-MailboxStatistics -Identity $Mailbox.Name
        $MailboxStats.Name = $Mailbox.DisplayName
    	$MailboxStats.Account = $Stats.LastLoggedOnUserAccount
        $MailboxStats.Database = $Mailbox.Database
        $MailboxStats.IssueWarningQuota = $Mailbox.IssueWarningQuota
        $MailboxStats.ProhibitSendQuota = $Mailbox.ProhibitSendQuota
        $MailboxStats.ProhibitSendReceiveQuota = $Mailbox.ProhibitSendReceiveQuota
    	$MailboxStats.ElementiCancellati = $Stats.TotalDeletedItemSize
        $MailboxStats.DimensioneTotale = $Stats.TotalItemSize
        $MailboxStats.NumeroMail = $Stats.ItemCount
        $MailboxStats.StorageLimitStatus = $Stats.StorageLimitStatus
    	$MailboxStats.LastLogonTime = $Stats.LastLogonTime
    	try {$MailboxStats.SpazioRimanente = ($Mailbox.ProhibitSendReceiveQuota - $Stats.TotalItemSize)} Catch { "Error on $($MailboxStats.Nome)"}
        $AllMailboxes += $MailboxStats
    }
    #creo csv 
    $AllMailboxes | Export-Csv C:\mailboxInfo.csv -NoTypeInformation -delimiter ';'

    Regards, 

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, January 2, 2019 5:41 AM
    Moderator

All replies

  • try get-mailbox -database "ABC"

    Chris

    Thursday, December 27, 2018 5:08 PM
  • Hi Chris, thx for help

    Please indicate me where put this string, i have many problem with powershell ...I'm not very confident

    Regards
    Angelo

    Thursday, December 27, 2018 5:16 PM
  • try this
    $AllMailboxes = @()
    $Mailboxes = Get-Mailbox -Database "CUSTOMER-DB1" -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime
    foreach ($Mailbox in $Mailboxes){
    


    Chris

    Friday, December 28, 2018 7:10 AM
  • Hi Angelo,

    If you just want to check information about mailboxes which hosted in a specific Database, you just need to modify the command below:

    $Mailboxes = Get-Mailbox -Database "CUSTOMER-DB1" -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime
    

    It will only check mailboxes that contained in CUSTOMER-DB1.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, December 28, 2018 8:06 AM
    Moderator
  • Hi,
    thx for replay

    The script works but i have this problem when execute:

    Get-MailboxStatistics : The specified mailbox "direzione"  isn't unique.
    At C:\Users\Administrator.DOMINIO\Desktop\Script\2.ps1:6 char:14
    +     $Stats = Get-MailboxStatistics -Identity $Mailbox.Alias
    +              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-MailboxStatistics], ManagementObjectAmbiguousException
        + FullyQualifiedErrorId : [Server=SRVEXCHANGE,RequestId=3160de38-7d79-43f7-aa5e-fd4573271669,TimeStamp=28/12/2018 08:17:44] [FailureCategory=Cmdlet-ManagementObjectAmbiguousException] 
        9838A373,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

    In another DB i have the ugual mailbox like info@customer1.com and info@customer2.com.

    For this reason in CSV the duplicate/similar mailbox don't export her statistics

    

    the problem could be this string:
    $ AllMailboxes = @ ()

    what is its function?

    Friday, December 28, 2018 8:26 AM
  • Hi Angelo,

    From this information below, we can know, there have two mailboxes have the same Alias:

    Get-MailboxStatistics : The specified mailbox "direzione"  isn't unique

    So, we should modify it as the script below:

    $AllMailboxes = @()
    $Mailboxes = Get-Mailbox -Database "CUSTOMER-DB1" -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Name, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime
    foreach ($Mailbox in $Mailboxes){
        $MailboxStats = "" | Select  Nome,Database,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,DimensioneTotale,ElementiCancellati,NumeroMail,StorageLimitStatus,Account,LastLogonTime,SpazioRimanente
        $Stats = Get-MailboxStatistics -Identity $Mailbox.Name
        $MailboxStats.Name = $Mailbox.DisplayName
    	$MailboxStats.Account = $Stats.LastLoggedOnUserAccount
        $MailboxStats.Database = $Mailbox.Database
        $MailboxStats.IssueWarningQuota = $Mailbox.IssueWarningQuota
        $MailboxStats.ProhibitSendQuota = $Mailbox.ProhibitSendQuota
        $MailboxStats.ProhibitSendReceiveQuota = $Mailbox.ProhibitSendReceiveQuota
    	$MailboxStats.ElementiCancellati = $Stats.TotalDeletedItemSize
        $MailboxStats.DimensioneTotale = $Stats.TotalItemSize
        $MailboxStats.NumeroMail = $Stats.ItemCount
        $MailboxStats.StorageLimitStatus = $Stats.StorageLimitStatus
    	$MailboxStats.LastLogonTime = $Stats.LastLogonTime
    	try {$MailboxStats.SpazioRimanente = ($Mailbox.ProhibitSendReceiveQuota - $Stats.TotalItemSize)} Catch { "Error on $($MailboxStats.Nome)"}
        $AllMailboxes += $MailboxStats
    }
    #creo csv 
    $AllMailboxes | Export-Csv C:\mailboxInfo.csv -NoTypeInformation -delimiter ';'

    Regards, 

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, January 2, 2019 5:41 AM
    Moderator
  • The function of "$AllMailboxes = @()" is to establish an empty array that gets added to later. It is not related to your error though. As you said, you have two users with the same Alias, therefore in your line that you run

    $Stats = Get-MailboxStatistics -Identity $mailbox.alias

    Try using:

    $Stats = Get-MailboxStatistics -Identity $mailbox.PrimarySmtpAddress

    Wednesday, January 2, 2019 5:47 AM
  • The function of "$AllMailboxes = @()" is to establish an empty array that gets added to later. It is not related to your error though. As you said, you have two users with the same Alias, therefore in your line that you run

    $Stats = Get-MailboxStatistics -Identity $mailbox.alias

    Try using:

    $Stats = Get-MailboxStatistics -Identity $mailbox.PrimarySmtpAddress

    Please notice this command below:

    $Mailboxes = Get-Mailbox -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime
    

    If you use "-Identity $mailbox.PrimarySmtpAddress", there will have an error says "Cannot bind argument to parameter 'Identity' because it is null". Because "PrimarySmtpAddress" doesn't in the select list for $Mailboxes, if you want to use it, you should add it to select list first.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, January 2, 2019 5:58 AM
    Moderator
  • You are indeed correct, Kyle. I usually don't do a "Select" statement if I'm assigning something to a variable. I know, it takes more memory and stuff, but my environment is small enough to where it doesn't matter, lol. So. Angelo, in line where you get all the mailboxes, replace this line:

    $Mailboxes = Get-Mailbox -Database "CUSTOMER-DB1" -ResultSize Unlimited | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Name, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime

    With this line:

    $Mailboxes = Get-Mailbox -Database "CUSTOMER-DB1" -ResultSize Unlimited | Select DisplayName, PrimarySmtpAddress, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Name, LastLoggedOnUserAccount, TotalDeletedItemSize,LastLogonTime

    Wednesday, January 2, 2019 6:07 AM
  • Thank you all for your help
    The script works

    Regards
    Angelo

    Friday, January 11, 2019 1:46 PM