none
Maths, Logic and Variables RRS feed

  • Question

  • Hello,

    I am trying to get some variables to give me some results for exchange when adding the mailbox total size and the archive total size added together they will give a result.

    Basically if the total item size of the mailbox and archive mailboxes are less than the size of the database or custom mailbox quotas then state the migration can take place. If they are greater than the total size then it will state that the mailbox quotas will need increasing. 

    My code is below if anyone can help: 

    $mbxStats = @() 
    $mailboxes = Get-Mailbox -ResultSize Unlimited
    foreach ($Mailbox in $mailboxes)
    {
        $stats = Get-MailboxStatistics -id $mailbox.DistinguishedName
        $MBDatabase = $mailbox.Database
        $Database = Get-MailboxDatabase $MBDatabase
        $DatabaseStats = Get-MailboxDatabase $MBDatabase -Status
        $ArchItemSize = $null
        $TotalMBSize = $null
        $CustMBSize = $null
        $DefMBSize = $null 
        
        $MBItemSize = '{0:N2}' -f  ($stats.TotalItemSize.Value.ToMB()/1024)
        
        if($mailbox.ProhibitSendReceiveQuota.Value -ne $null){
        $CustMBSize = '{0:N2}' -f ($mailbox.ProhibitSendReceiveQuota.Value.ToMB()/1024)
        $CustWarnSize = '{0:N2}' -f  ($mailbox.IssueWarningQuota.Value.ToMB()/1024)
        $CustSendSize = '{0:N2}' -f  ($mailbox.ProhibitSendQuota.Value.ToMB()/1024)
        }
        
        $DefMBSize = '{0:N2}' -f  ($Database.ProhibitSendReceiveQuota.Value.ToMB()/1024)
        $DefDBSize = '{0:N2}' -f  ($DatabaseStats.DatabaseSize.ToMB()/1024)
        $DefWarnSize = '{0:N2}' -f  ($Database.IssueWarningQuota.Value.ToMB()/1024)
        $DefSendSize = '{0:N2}' -f  ($Database.ProhibitSendQuota.Value.ToMB()/1024)
        
        
        $mbx = New-Object System.Object
        $mbx | Add-Member -MemberType NoteProperty -Value $stats.Displayname -Name DisplayName
        $mbx | Add-Member -MemberType NoteProperty -Value $MBItemSize -Name "MailboxTotalSize(GB)"
         
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "DefaultIssueWarningGB"
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "DefaultProhibitSendGB"
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "DefaultMailboxSizeGB"
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "CustomIssueWarningGB"
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "CustomProhibitSendGB"
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "CustomMailboxSizeGB" 
            
        if($mailbox.UseDatabaseQuotaDefaults -eq $true){ 
        $mbx.DefaultIssueWarningGB = $DefWarnSize
        $mbx.DefaultProhibitSendGB = $DefSendSize
        $mbx.DefaultMailboxSizeGB = $DefMBSize
        }
    
        if($mailbox.ProhibitSendReceiveQuota.Value -ne $null){ 
        $mbx.CustomIssueWarningGB = $CustWarnSize
        $mbx.CustomProhibitSendGB = $CustSendSize
        $mbx.CustomMailboxSizeGB =  $CustMBSize  
        }
        
        $mbx | Add-Member -MemberType NoteProperty -Value $mailbox.Database.Name -Name MailboxDatabase
        $mbx | Add-Member -MemberType NoteProperty -Value $Database.Server.Name -Name MailboxDatabaseServer
        $mbx | Add-Member -MemberType NoteProperty -Value $Database.EdbFilePath.PathName -Name MailboxDatabaseLocation
        $mbx | Add-Member -MemberType NoteProperty -Value $DefDBSize -Name "MailboxDatabaseSizeGB"
               
        if($mailbox.ArchiveDatabase -ne $null){ 
        
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "ArchiveTotalSizeGB"
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "ArchiveWarningGB"
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name "ArchiveQuotaGB"
            
        $ArchiveStats = Get-MailboxStatistics -id $mailbox.DistinguishedName -Archive
        $ArDatabase = $ArchiveStats.Database.Name
        $ArchDatabase = Get-MailboxDatabase $ArDatabase  
        $ArchDatabaseStats = Get-MailboxDatabase $ArDatabase -Status
        
        $ArchItemSize = '{0:N2}' -f  ($ArchiveStats.TotalItemSize.Value.ToMB()/1024)
        $ArchQuotaSize = '{0:N2}' -f  ($mailbox.ArchiveQuota.Value.ToMB()/1024)
        $ArchWarnSize = '{0:N2}' -f  ($mailbox.ArchiveWarningQuota.Value.ToMB()/1024)
        $ArchDBSize = '{0:N2}' -f  ($ArchDatabaseStats.DatabaseSize.ToMB()/1024)
              
        $mbx.ArchiveTotalSizeGB = $ArchItemSize 
        $mbx.ArchiveWarningGB = $ArchWarnSize
        $mbx.ArchiveQuotaGB = $ArchQuotaSize
        $mbx | Add-Member -MemberType NoteProperty -Value $mailbox.ArchiveDatabase.Name -Name ArchiveDatabase
        $mbx | Add-Member -MemberType NoteProperty -Value $ArchDatabase.Server.Name -Name ArchiveDatabaseServer
        $mbx | Add-Member -MemberType NoteProperty -Value $ArchDatabase.EdbFilePath.PathName -Name ArchiveDatabaseLocation
        $mbx | Add-Member -MemberType NoteProperty -Value $ArchDBSize -Name "ArchiveDatabaseSize(GB)"
        }
        
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name Migrate 
        $mbx | Add-Member -MemberType NoteProperty -Value $null -Name UpdateMailboxSize
        
        [int]$TotalMBSize = [int]$MBItemSize
        
        if($ArchItemSize -ne $null){   
        [int]$TotalMBSize = [int]$MBItemSize + [int]$ArchItemSize
        }
            
        if([int]$TotalMBSize -le [int]$DefMBSize -and [int]$TotalMBSize -le [int]$CustMBSize) {
        $mbx.Migrate = "Migration Authorised"
        }
        
        if([int]$TotalMBSize -gt [int]$DefMBSize -or [int]$TotalMBSize -gt [int]$CustMBSize){
        $mbx.UpdateMailboxSize = "Update Required"
        }    
             	    
        $mbxStats += $mbx
    }  

    Any help would be appreciated. The trouble is in the last few lines where the "Update Required" and "Migration Authorised"

    Thanks

    James

    • Moved by Bill_Stewart Friday, December 29, 2017 9:00 PM This is not "fix/debug/rewrite my script for me" forum
    Friday, September 15, 2017 4:06 PM

All replies