Skip to content

Instantly share code, notes, and snippets.

@jamiechalmerzlp
Last active August 7, 2024 08:38
Show Gist options
  • Save jamiechalmerzlp/f17938ede37643b6a46574cb8f9f895e to your computer and use it in GitHub Desktop.
Save jamiechalmerzlp/f17938ede37643b6a46574cb8f9f895e to your computer and use it in GitHub Desktop.
## CONNECT TO EXCHANGE ONLINE POWERSHELL OR USE EXCHANGE MANAGEMENT SHELL FOR ON-PREMISES EXCHANGE
if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {
Write-Host "ExchangeOnlineManagement module is not installed. Installing it..."
## INSTALL THE EXCHANGEONLINEMANAGEMENT MODULE FROM THE POWERSHELL GALLERY
Install-Module -Name ExchangeOnlineManagement -Force -Scope CurrentUser
if ($?) {
Write-Host "ExchangeOnlineManagement module has been successfully installed." -ForegroundColor Green
} else {
Write-Host "Failed to install the ExchangeOnlineManagement module." -ForegroundColor Red
}
} else {
Write-Host "ExchangeOnlineManagement module is already installed." -ForegroundColor DarkGreen
}
## ENTER THE ADDRESS OF THE MAILBOX TO QUERY
$mailbox = Read-Host "Enter the Email Address:"
## GET ALL INBOX RULES FOR THE SPECIFIED MAILBOX
$inboxRules = Get-InboxRule -Mailbox $mailbox
## LOOP THROUGH EACH RULE AND DISPLAY DETAILED INFORMATION
foreach ($rule in $inboxRules) {
Write-Output "Rule Name: $($rule.Name)"
Write-Output "Priority: $($rule.Priority)"
Write-Output "Enabled: $($rule.Enabled)"
Write-Output "Description: $($rule.Description)"
## DISPLAY CONDITIONS, ACTIONS, AND EXCEPTIONS IN DETAIL
if ($rule.Conditions) {
Write-Output "Conditions:"
$rule.Conditions | Format-List | Out-String | Write-Output
}
if ($rule.Actions) {
Write-Output "Actions:"
$rule.Actions | Format-List | Out-String | Write-Output
}
if ($rule.Exceptions) {
Write-Output "Exceptions:"
$rule.Exceptions | Format-List | Out-String | Write-Output
}
Write-Output "--------------------------------"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment