<# ============================================================================================= Name: Export all shared mailboxes in Office 365 Version: 1.0 Website: o365reports.com Script by: O365Reports Team For detailed script execution: https://o365reports.com/2022/07/13/get-shared-mailbox-in-office-365-using-powershell Script Execution Methods: To run this script, you can choose any of the methods below. The exported report will contain all the shared mailboxes in Office 365 and their properties to CSV file. Method 1: To run the script with an MFA and non-MFA accounts, .\GetSharedMailboxReport.ps1 Method 2: To schedule the script using the non-MFA account, If the admin account has MFA, you must disable MFA using the Conditional Access policy to make the script work. .\GetSharedMailboxReport.ps1 -UserName admin@o365reorts.com -Password XXX Method 3: To find shared mailboxes with licenses, execute the script with the –LicensedOnly switch parameter. You can download our dedicated script on licensed shared mailbox report to get more detailed shared mailboxes with licenses. .\GetSharedMailboxReport.ps1 -LicensedOnly Method 4: To identify shared mailboxes with auto-email forwarding configurations, run the script with –EmailForwardingEnabled switch param. .\GetSharedMailboxReport.ps1 -EmailForwardingEnabled ============================================================================================ #>Param ( [Parameter(Mandatory = $false)] [switch]$LicensedOnly, [switch]$EmailForwardingEnabled, [switch]$FullAccessOnly, [string]$UserName, [string]$Password ) Function Connect_Exo { #Check for EXO v2 module inatallation $Module = Get-Module ExchangeOnlineManagement -ListAvailable if($Module.count -eq 0) { Write-Host Exchange Online PowerShell V2 module is not available -ForegroundColor yellow $Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No if($Confirm -match "[yY]") { Write-host "Installing Exchange Online PowerShell module" Install-Module ExchangeOnlineManagement -Repository PSGallery -AllowClobber -Force Import-Module ExchangeOnlineManagement } else { Write-Host EXO V2 module is required to connect Exchange Online.Please install module using Install-Module ExchangeOnlineManagement cmdlet. Exit } } Write-Host Connecting to Exchange Online... #Storing credential in script for scheduling purpose/ Passing credential as parameter - Authentication using non-MFA account if(($UserName -ne "") -and ($Password -ne "")) { $SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force $Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword Connect-ExchangeOnline -Credential $Credential } else { Connect-ExchangeOnline } } Connect_Exo $OutputCSV=".\SharedMailboxReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv" $Count=0 $OutputCount=0 $ExportResult="" $ExportResults=@() #Retrieve all the shared mailboxes Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox | foreach { $Print=$true $Count++ $Name=$_.Name Write-Progress -Activity "`n Processing $Name.."`n" Processed mailbox count: $Count" $PrimarySMTPAddress=$_.PrimarySMTPAddress $UPN=$_.UserPrincipalName $Alias=$_.Alias $ArchiveStatus=$_.ArchiveStatus $LitigationHold=$_.LitigationHoldEnabled $RetentionHold=$_.RetentionHoldEnabled $IsLicensed=$_.SkuAssigned $AuditEnabled=$_.AuditEnabled $HideFromAddressList=$_.HiddenFromAddressListsEnabled $ForwardingAddress=$_.ForwardingAddress $ForwardingSMTPAddress=$_.ForwardingSMTPAddress if($ForwardingAddress -eq $null) { $ForwardingAddress="-" } if($ForwardingSMTPAddress -eq $null) { $ForwardingSMTPAddress="-" } $MBSize=((Get-MailboxStatistics -Identity $UPN).totalItemSize.value) $MailboxSize=$MBSize.ToString().split("(") | Select-Object -Index 0 If(($LicensedOnly.IsPresent) -and ($IsLicensed -eq $false)) { $Print=$false } if(($EmailForwardingEnabled.IsPresent) -and (($ForwardingAddress -eq "-")-and ($ForwardingSMTPAddress -eq "-"))) { $Print=$false } #Export result to csv if($Print -eq $true) { $OutputCount++ $ExportResult=@{'Name'=$Name;'Primary SMTP Address'=$PrimarySMTPAddress;'Alias'=$Alias;'MB Size'=$MailboxSize;'Is Licensed'=$IsLicensed ;'Archive Status'=$ArchiveStatus;'Hide From Address List'=$HideFromAddressList;'Audit Enabled'=$AuditEnabled; 'Forwarding Address'=$ForwardingAddress;'Forwarding SMTP Address'=$ForwardingSMTPAddress;'Litigation Hold'=$LitigationHold;'Retention Hold'=$RetentionHold} $ExportResults= New-Object PSObject -Property $ExportResult $ExportResults | Select-Object 'Name','Primary SMTP Address','Alias','MB Size','Is Licensed','Archive Status','Hide From Address List','Audit Enabled','Forwarding Address','Forwarding SMTP Address','Litigation Hold','Retention Hold' | Export-Csv -Path $OutputCSV -Notype -Append } } #Open output file after execution If($OutputCount -eq 0) { Write-Host No records found } else { Write-Host `nThe output file contains $OutputCount shared mailboxes. if((Test-Path -Path $OutputCSV) -eq "True") { Write-Host `nThe Output file available in $OutputCSV -ForegroundColor Green $Prompt = New-Object -ComObject wscript.shell $UserInput = $Prompt.popup("Do you want to open output file?",` 0,"Open Output File",4) If ($UserInput -eq 6) { Invoke-Item "$OutputCSV" } } } #Disconnect Exchange Online session Disconnect-ExchangeOnline -Confirm:$false -InformationAction Ignore -ErrorAction SilentlyContinue