M365 Powershell

Microsoft 365 : Shared Mailbox Report

August 25, 2020

author:

Microsoft 365 : Shared Mailbox Report

Sometimes it’s useful to run a report on shared mailboxes. This tiny script creates a often helpful excel file.

#requires -version 2
<#
.SYNOPSIS
  get Mailbox Details shared
.DESCRIPTION
  get Mailbox Details shared
.NOTES
  Version:        1.0
  Author:         Pascal Briner
  Creation Date:  20.03.2020
  Purpose/Change: Initial script development
 #>

#---------------------------------------------------------[Initialisations]--------------------------------------------------------

#---------------------------------------------------------[Authentication]--------------------------------------------------------
# Use Authentication/m365-mfa-exo.ps1 to authenticate

#----------------------------------------------------------[Declarations]----------------------------------------------------------
$ExportFile = "C:\temp\getMailboxDetailsShared.csv"
$Results = @()
$MailboxUsers = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox

$i = 0
#-----------------------------------------------------------[Functions]------------------------------------------------------------


#-----------------------------------------------------------[Execution]------------------------------------------------------------
Write-Host "***********************************" -ForegroundColor Blue
Write-Host "Working on mailbox details .." -ForegroundColor Blue
Write-Host "***********************************" -ForegroundColor Blue

try{
    foreach($user in $MailboxUsers){
                $i++
                Write-Host "Working on user : "$user.userprincipalname -ForegroundColor Yellow
                $Properties = @{
                Name = $user.name
                ForwardingAddress = $user.ForwardingSMTPAddress
                Alias = $user.alias
                RetainDeletedItemsFor = $user.RetainDeletedItemsFor
                UsageLocation = $user.usagelocation
                ArchiveStatus = $user.archivestatus
                MessageCopy = $user.MessageCopyForSendOnBehalfEnabled
                MessageSendAs = $user.MessageCopyForSentAsEnabled

                }
                $Results += New-Object psobject -Property $properties

        }
    
    Write-Host "Building Export File ..." -ForegroundColor Blue
    $Results | Select-Object Name,Alias,ForwardingAddress,UsageLocation,ArchiveStatus,RetainDeletedItemsFor,MessageCopy,MessageSendAs  | Export-Csv -notypeinformation -Path $ExportFile
    Invoke-Item $ExportFile

}catch{
    Write-Host "Something went wrong" -ForegroundColor Red
    Write-Warning $Error[0]

}
Leave a comment