none
Exchange 2010 Mailbox report RRS feed

  • Question

  • Colleague of ours wrote script that worked prefectly when we had 1 Mailbox Database. Nnow we need to rewrite so that it supports multiple database.

    #Import posh module with Exchange Cmdlet.
    
    function Load_Exchange_Tools {
    	if (-not (Get-pssnapin | ? {$_.name -like 'Microsoft.Exchange.Management.PowerShell.e2010'})) {
    		Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010
    	}
    }
    
    #Formatting ps & r quota for a given pure integer ID to verify whether he might have quota "unlimited" = mailbox default.
    # This is for calculating percent later
    
    function qweqwe ($s) {
    [string]$qwe = (get-mailbox -id $s).prohibitsendreceivequota
    IF ($qwe -eq "unlimited") {[int]$qwe = [int]$defaultmailboxlimit} Else {$qwe = ($qwe.Split("(")[1].Split(" ")[0].Replace(",",""))};$qwe}
    
    #Formatting ps & r quota exchange value for a given ID to verify whether he might have quota "unlimited" = default mailbox ergo "mb = default".
    
    function sendreceive ($s) {
    [string]$qwe = (get-mailbox -id $s).prohibitsendreceivequota
    IF ($qwe -eq "unlimited") {$qwe = [string]($defaultmailboxlimit/1MB) + " MB = Default" };$qwe}
    
    #Formatting prohibitsend quota exchange value for a given ID to verify whether he might have quota "unlimited" = maiblox default ergo "mb = default".
    
    function send ($s) {
    [string]$qwe = (get-mailbox -id $s).prohibitsendquota
    IF ($qwe -eq "unlimited") {$qwe = [string]($defaultmailboxlimit/1MB) + " MB = Default" };$qwe}
    
    #Text that will go in the mail body
    
    $Day = (Get-Date).day
    $Month = (Get-Date).month
    $Year = (Get-Date).Year
    $mailbox1 = "Report on the mailbox for the day $Day/$Month/$Year`n"
    # $mailbox11 = "`nReport on available space C:\ partition on computer in test.test domain`n"
    $mailbox3 = [string]::join([environment]::NewLine, (get-content c:\scripts\HR-Alerts.txt))
    $mailbox2 = [string]::join([environment]::NewLine, (get-content \\test\logonstats\LowDiskSpace.txt))
    Load_Exchange_Tools
    #Get-MailboxStatistics -database mbx01 | Sort-Object TotalItemSize -Descending | Select DisplayName, @{expression={$_.TotalItemSize.value.ToMB()}}, ItemCount, #StorageLimitStatus, TotalDeletedItemSize, DeletedItemCount, LastLogonTime, LastLogoffTime, LastLoggedOnUserAccount | Export-CSV -Force c:\scripts\izvestaj.csv
    
    #Taking pure integers for default mailbox quota mbx01 base.
    
    $defaultmailboxlimit =  ([string](Get-MailboxDatabase -id mbx01).ProhibitSendReceiveQuota).Split("(")[1].Split(" ")[0].Replace(",","") 
       
    
    #Create and export to CSV format totalitemsize, prohibitsend, and adding prohibitsendreceive percent used, using function for it.
    #ampersands are there so that this one-liner looks like something understandable. delimiter is the tab so that excel can open table in the right way by default
    
    Get-Mailbox | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select `
    Database,`
    DisplayName,`
    @{name="Total Item Size";expression={[string]($_.TotalItemSize.value.ToMB())}},`
    ItemCount,`
    StorageLimitStatus,`
    @{name="Percent used quota";expression={[string]([math]::Round(((([string]$_.TotalItemSize).Split("(")[1].Split(" ")[0].Replace(",","")))/(qweqwe ($_.displayname)),2)*100) + "%"}},`
    @{name="prohibit send quota";expression={send ($_.displayname)}},`
    @{name="prohibit send&receive quota";expression={sendreceive ($_.displayname)}},`
    TotalDeletedItemSize,`
    DeletedItemCount,`
    LastLogonTime,`
    LastLogoffTime,`
    LastLoggedOnUserAccount | export-csv -force -notype -encoding unicode -delimiter "	" -path c:\scripts\reportZ.csv
    
    

    we have tried to solv problem with this but it didnt work:

    $dbs = Get-MailBoxDatabase -id *
    
    $defaultmailboxlimit = foreach ($db in $dbs) { ([string](Get-MailboxDatabase -id $db.Name).ProhibitSendReceiveQuota).Split("(")[1].Split(" ")[0].Replace(",","") }

    Can anyone help

    • Moved by Bill_Stewart Thursday, January 2, 2014 7:29 PM Question outside reasonable forum scope
    Monday, November 4, 2013 11:17 AM

All replies

  • How about using this? Please test and use this

    $dbs = Get-MailboxDatabase -Server <ServerName>
    foreach($id in $dbs)
    {
    
    "Your activity code goes here"
    }


    Regards Chen V

    Monday, November 4, 2013 11:43 AM
  • Still the same.

    Get empty cells in excel report.

    Monday, November 4, 2013 1:02 PM
  • Still the same.

    Get empty cells in excel report.

    What have you tried?

    Do you have anyone who is trained in Exchange?

    Do you have anyone who knows PowerShell?


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 1:15 PM
  • We have tried :

    $defaultmailboxlimit = foreach ($id in $dbs) { ([string](Get-MailboxDatabase -id $id).ProhibitSendReceiveQuota).Split("(")[1].Split(" ")[0].Replace(",","") }

    also

    $defaultmailboxlimit = foreach ($id in $dbs) { ([string](Get-MailboxDatabase -id $id.Name).ProhibitSendReceiveQuota).Split("(")[1].Split(" ")[0].Replace(",","") }

    We have knowledge about Exchange and some basic knowledge about Powershell.

    Monday, November 4, 2013 1:27 PM
  • The code as written seems to get all mailboxes on the server.  It is not database targeted.

    Are you saying that something is missing or are you asking how to include the per database statistics?

    "Get-Mailbox | Get-MaiboxStatistics" gets the sstatistics for all mailboxes on the server.


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 1:34 PM
  • This is a script that creates CSV report.

    In this report we get imformation like Total Item Size ,Prohibit Send & Receive Quota , we compare the vaules so that we can get precentage about used quota.

    It worked perfectly when we had only one mailbox database , now we need to rewrite the script so that it includes all mailbox databases (recently we have added few more databases).

    Currently report generates empty cells  for Prohibit Send & Receive Qouta , Prohibit Send Qouta and Percent Used Quota cells for mailboxes that are using database default values for Quotas.

    For mailboxes that are not using database level configured quotas , but have specific quotas defined, we get correct results in cells .

    We need to get results for users that have database default qoutas.

    Monday, November 4, 2013 1:48 PM
  • This tool may meet your requirements. But no source code provided please check this to accomplish your tasks

    Regards Chen V

    Monday, November 4, 2013 2:07 PM
  • We have tried :

    $defaultmailboxlimit = foreach ($id in $dbs) { ([string](Get-MailboxDatabase -id $id).ProhibitSendReceiveQuota).Split("(")[1].Split(" ")[0].Replace(",","") }

    also

    $defaultmailboxlimit = foreach ($id in $dbs) { ([string](Get-MailboxDatabase -id $id.Name).ProhibitSendReceiveQuota).Split("(")[1].Split(" ")[0].Replace(",","") }

    We have knowledge about Exchange and some basic knowledge about Powershell.

    Why do you think you need to change this. The report is kind of incorrect but it does report on all mailboxes in the domain. It does not have any references to the database and does not need any from what I can see.

    What is it that the report does not do?


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 2:50 PM
  • This is a script that creates CSV report.

    In this report we get imformation like Total Item Size ,Prohibit Send & Receive Quota , we compare the vaules so that we can get precentage about used quota.

    It worked perfectly when we had only one mailbox database , now we need to rewrite the script so that it includes all mailbox databases (recently we have added few more databases).

    Currently report generates empty cells  for Prohibit Send & Receive Qouta , Prohibit Send Qouta and Percent Used Quota cells for mailboxes that are using database default values for Quotas.

    For mailboxes that are not using database level configured quotas , but have specific quotas defined, we get correct results in cells .

    We need to get results for users that have database default qoutas.

    So you are saying that you want to adjust it to retrieve the mailbox database?  Does each database actually have different quotas?

    To accomplish this would require a restructuring of the approach which should be done anyway.  The current script is probably very slow because it makes repeated calls to the system to get simple pieces on information.


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 2:53 PM
  • This is how we need to unwind the information so it is reportable.  You will see that this runs much faster.  We canthen feed it into the formatter which also needs a couple of changes.

    $statistics=Get-MailBox |
       ForEach-Object{
         $mb=Get-MailBoxStatistics $_
         $mb|Add-Member -MemberType NoteProperty -Name ProhibitSendQuota -value $_.prohibitsendquota
         $mb|Add-Member -MemberType NoteProperty -Name ProhibitSendReceiveQuota -value $_.prohibitsendreceivequota
         $mb
    } 
    
    


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 2:57 PM
  • #Import posh module with Exchange Cmdlet.
    function Load_Exchange_Tools {
    	if (-not (Get-pssnapin | ? {$_.name -like 'Microsoft.Exchange.Management.PowerShell.e2010'})) {
    		Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010
    	}
    }
    
    $statistics=Get-MailBox |
       ForEach-Object{
         $mb=Get-MailBoxStatistics $_
         $mb|Add-Member -MemberType NoteProperty -Name ProhibitSendQuota -value $_.prohibitsendquota
         $mb|Add-Member -MemberType NoteProperty -Name ProhibitSendReceiveQuota -value $_.prohibitsendreceivequota
         $mb
    } 
    
    $statistics |
        Sort-Object TotalItemSize -Descending | 
    	    Select `
        		Database,`
        		DisplayName,`
        		@{name="Total Item Size";expression={[string]($_.TotalItemSize.value.ToMB())}},`
        		ItemCount,`
                ProhibitSendQuota,
                ProhibitSendReceiveQuota,
        		StorageLimitStatus,`
        		TotalDeletedItemSize,`
        		DeletedItemCount,`
        		LastLogonTime,`
        		LastLogoffTime,`
        		LastLoggedOnUserAccount | 
    	Format-Table -AutoSize

    This is very fast and has nearly everything you need.  We can add the formatters in next:


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 3:26 PM
  • This gets all database quotas to be used in formatter.

    $mbdbs=foreach($db in Get-MailboxDatabase){
        @{$db.Name=$db.ProhibitSendReceiveQuota.Value}
    } 
    

    Now we can use the database name to get the quota settings without a repeated call to the database.


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 3:37 PM
  • Adding that in and refactoring for simplicity:

    $mbdbs=foreach($db in Get-MailboxDatabase){
        @{$db.Name=$db.ProhibitSendReceiveQuota.Value}
    } 
    
    $statistics=Get-MailBox |
       ForEach-Object{
         $mb=Get-MailBoxStatistics $_
         $mb|Add-Member -MemberType NoteProperty -Name ProhibitSendQuota -value $_.prohibitsendquota
         $mb|Add-Member -MemberType NoteProperty -Name ProhibitSendReceiveQuota -value $_.prohibitsendreceivequota
         $mb
    } 
    $props=@(
        Database,
        DBProhibitSendReceiveQuota=mbdbs[$_.Database.Name]
        DisplayName,
        @{name="Total Item Size";expression={[string]($_.TotalItemSize.value.ToMB())}},
        ItemCount,
        ProhibitSendQuota,
        ProhibitSendReceiveQuota,
        StorageLimitStatus,
        TotalDeletedItemSize,
        DeletedItemCount,
        LastLogonTime,
        LastLogoffTime,
        LastLoggedOnUserAccount 
    )
    
    
    $statistics |
        Sort-Object TotalItemSize -Descending | 
    	Select-Object -Property $prop | 
    	Format-Table -AutoSize
    
    

    Notice now that each statistic record contains both the mailbox value and the database setting. These can now be used to generate simple perrcentages.


    ¯\_(ツ)_/¯

    Monday, November 4, 2013 3:41 PM