Sunday, September 8, 2024
HomePowershellWorkplace 365 / Alternate On-line Mailbox Dimension Report Together with Mailbox Free...

Workplace 365 / Alternate On-line Mailbox Dimension Report Together with Mailbox Free House with PowerShell – The Lazy Administrator


I wished to create an automatic alert that will notify me of Workplace 365 mailboxes that have been approaching full, and located a terrific PowerShell reporting script by Ruud (LazyAdmin.nl). If in case you have not checked out his weblog, cease studying now and head on over there. There’s a ton of nice scripts and write ups! The script connects to your Workplace 365 setting and exports the next:

  • Show title
  • Major E-mail deal with
  • Mailbox sort
  • Final consumer motion time
  • Whole mailbox dimension
  • Mailbox Free House (NEW!)
  • Deleted merchandise dimension
  • Merchandise Depend
  • Deleted Merchandise Depend
  • Situation Warning Dimension
  • Prohibit Ship Obtain Quota (max mailbox dimension)
  • Archive dimension (if the consumer has an archive)
  • Archive Merchandise Depend
  • Archive Mailbox Free House (NEW!)
  • Archive Deleted Merchandise Depend
  • Archive warning quota
  • Archive quota

 

Shared Mailboxes

It additionally permits you to filter the mailbox sort that you simply need to collect outcomes for. By default, Shared Mailboxes are included, however you’ll be able to filter this by calling the -SharedMailboxes parameter.

The code block beneath will solely collect outcomes for Shared Mailboxes

The code block beneath will exclude shared mailboxes

The code block beneath will embody each consumer and shared mailboxes. (Default)

Archive Mailboxes

Archive Mailboxes are included by default. By calling the -Archive parameter you’ll be able to exclude them.

New Additions

I went to his GitHub and forked his repo and made the next modifications:

  • All values are actually int32 as an alternative of strings. Some values could be “30 GB” whereas others have been integers like “30”
  • Exporting the outcomes to CSV file is now non-compulsory, this enables an administrator to view the report straight within the shell
  • I added ‘Mailbox Free House’ so we will rapidly view how a lot free house every mailbox at present has
  • I added ‘Archive Mailbox Free House*’ however added an asterisk as many Workplace 365 licenses have ‘comfortable limits’ on the archive mailbox and as you method that restrict it should auto-expand itself. I personally don’t have any worth on viewing the archive mailbox free house dimension as a result of that purpose however I wished to incorporate it as some directors may have reporting on this.

Code

The code might be discovered on GitHub however as at all times, I may even paste it right here. To make sure that you’re utilizing the newest model its really useful to at all times get the code through GitHub. I additionally submitted a Pull Request to the unique repo.

<#
.SYNOPSIS
  Create report of all mailbox and archive sizes
.DESCRIPTION
  Collects all of the mailbox and archive stats from Alternate On-line customers. By default it should additionally
  embody the Shared Mailboxes. 
.EXAMPLE
  Get-MailboxSizeReport.ps1
  Generate the mailbox dimension report with Shared mailboxes, mailbox archive.
.EXAMPLE
  Get-MailboxSizeReport.ps1 -sharedMailboxes solely
  Get solely the shared mailboxes
.EXAMPLE
  Get-MailboxSizeReport.ps1 -sharedMailboxes no
  Get solely the consumer mailboxes
.EXAMPLE
  Get-MailboxSizeReport.ps1 -archive:$false
  Get the mailbox dimension with out the archive mailboxes
.EXAMPLE
  Get-MailboxSizeReport.ps1 -CSVpath c:tempreport.csv
  Retailer CSV report in c:tempreport.csv
.EXAMPLE
  Get-MailboxSizeReport.ps1 | Format-Desk
  Print outcomes for mailboxes within the console and format as desk
.NOTES
  Model:        1.3
  Creator:         R. Mens - LazyAdmin.nl
  Modified By:    Bradley Wyatt - The Lazy Administrator
  Creation Date:  23 sep 2021
  Modified Date:  26 aug 2022
  Goal/Change: Test if now we have a mailbox, earlier than working the numbers
  Hyperlink:           https://lazyadmin.nl/powershell/office-365-mailbox-size-report
#>

param(
  [Parameter(
    Mandatory = $true,
    HelpMessage = "Enter the Exchange Online or Global admin username"
  )]
  [string]$adminUPN,

  [Parameter(
    Mandatory = $false,
    HelpMessage = "Get (only) Shared Mailboxes or not. Default include them"
  )]
  [ValidateSet("no", "only", "include")]
  [string]$sharedMailboxes = "embody",

  [Parameter(
    Mandatory = $false,
    HelpMessage = "Include Archive mailboxes"
  )]
  [switch]$archive = $true,

  [Parameter(
    Mandatory = $false,
    HelpMessage = "Enter path to save the CSV file"
  )]
  [string]$CSVpath
)

Operate ConnectTo-EXO {
  <#
    .SYNOPSIS
        Connects to EXO when no connection exists. Checks for EXO v2 module
  #>
  
  course of {
    # Test if EXO is put in and join if no connection exists
    if ($null -eq (Get-Module -ListAvailable -Title ExchangeOnlineManagement))
    {
      Write-Host "Alternate On-line PowerShell v2 module is required, do you need to set up it?" -ForegroundColor Yellow
      
      $set up = Learn-Host Do you need to set up module? [Y] Sure [N] No 
      if($set up -match "[yY]") 
      { 
        Write-Host "Putting in Alternate On-line PowerShell v2 module" -ForegroundColor Cyan
        Set up-Module ExchangeOnlineManagement -Repository PSGallery -AllowClobber -Drive
      } 
      else
      {
	      Write-Error "Please set up EXO v2 module."
      }
    }


    if ($null -ne (Get-Module -ListAvailable -Title ExchangeOnlineManagement)) 
    {
	    # Test if there's a energetic EXO classes
	    $psSessions = Get-PSSession | Choose-Object -Property State, Title
	    If (((@($psSessions) -like '@{State=Opened; Title=ExchangeOnlineInternalSession*').Depend -gt 0) -ne $true) {
		    Join-ExchangeOnline -UserPrincipalName $adminUPN
	    }
    }
    else{
      Write-Error "Please set up EXO v2 module."
    }
  }
}

Operate Get-Mailboxes {
  <#
    .SYNOPSIS
        Get all of the mailboxes for the report
  #>
  course of {
    swap ($sharedMailboxes)
    {
      "embody" {$mailboxTypes = "UserMailbox,SharedMailbox"}
      "solely" {$mailboxTypes = "SharedMailbox"}
      "no" {$mailboxTypes = "UserMailbox"}
    }

    Get-EXOMailbox -ResultSize limitless -RecipientTypeDetails $mailboxTypes -Properties IssueWarningQuota, ProhibitSendReceiveQuota, ArchiveQuota, ArchiveWarningQuota, ArchiveDatabase | 
      Choose-Object UserPrincipalName, DisplayName, PrimarySMTPAddress, RecipientType, RecipientTypeDetails, IssueWarningQuota, ProhibitSendReceiveQuota, ArchiveQuota, ArchiveWarningQuota, ArchiveDatabase
  }
}

Operate ConvertTo-Gb {
  <#
    .SYNOPSIS
        Convert mailbox dimension to Gb for uniform reporting.
  #>
  param(
    [Parameter(
      Mandatory = $true
    )]
    [string]$dimension
  )
  course of {
    if ($dimension -ne $null) {
      $worth = $dimension.Break up(" ")

      swap($worth[1]) {
        "GB" {$sizeInGb = ($worth[0])}
        "MB" {$sizeInGb = ($worth[0] / 1024)}
        "KB" {$sizeInGb = ($worth[0] / 1024 / 1024)}
      }

      return [Math]::Spherical($sizeInGb,2,[MidPointRounding]::AwayFromZero)
    }
  }
}


Operate Get-MailboxStats {
  <#
    .SYNOPSIS
        Get the mailbox dimension and quota
  #>
  course of {
    $mailboxes = Get-Mailboxes
    $i = 0

    $mailboxes | ForEach-Object {

      # Get mailbox dimension     
      $mailboxSize = Get-MailboxStatistics -identity $_.UserPrincipalName | Choose-Object TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount,LastUserActionTime

      if ($null -ne $mailboxSize) {
      
        # Get archive dimension if it exists and is requested
        $archiveSize = 0
        $archiveResult = $null

        if ($archive.IsPresent -and ($null -ne $_.ArchiveDatabase)) {
          $archiveResult = Get-EXOMailboxStatistics -UserPrincipalName $_.UserPrincipalName -Archive | Choose-Object ItemCount,DeletedItemCount,@{Title = "TotalArchiveSize"; Expression = {$_.TotalItemSize.ToString().Break up("(")[0]}}
          if ($null -ne $archiveResult) {
            $archiveSize = ConvertTo-Gb -size $archiveResult.TotalArchiveSize
          }else{
            $archiveSize = 0
          }
        }  
    
        [pscustomobject]@ Choose-Object -First 1
          "Archive Quota (GB)" = ConvertTo-Gb -size $_.ArchiveQuota.ToString().Break up("(")[0]
        

        $currentUser = $_.DisplayName
        Write-Progress -Exercise "Accumulating mailbox standing" -Standing "Present Depend: $i" -PercentComplete (($i / $mailboxes.Depend) * 100) -CurrentOperation "Processing mailbox: $currentUser"
        $i++;
      }
    }
  }
}

# Hook up with Alternate On-line
ConnectTo-EXO

If ($CSVpath) {
    # Get mailbox standing
    Get-MailboxStats | Export-CSV -Path $CSVpath -NoTypeInformation -Encoding UTF8
    if ((Get-Merchandise $CSVpath).Size -gt 0) {
        Write-Host "Report completed and saved in $CSVpath" -ForegroundColor Inexperienced
    } 
    else {
        Write-Host "Didn't create report" -ForegroundColor Crimson
    }
}
Else {
    Get-MailboxStats
}
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments