Repository: microsoft/CSS-Exchange
File: Calendar/Get-RBASummary.ps1 (PowerShell)

Code before:
    # check we get a response
    if ($null -eq $Mailbox) {
        Write-Host -ForegroundColor Red "Get-Mailbox returned null. Make sure you Import-Module ExchangeOnlineManagement and  Connect-ExchangeOnline. Exiting script.";
        exit;
    } else {
        if ($Mailbox.RecipientTypeDetails -ne "RoomMailbox" -and $Mailbox.RecipientTypeDetails -ne "EquipmentMailbox") {
            Write-Host -ForegroundColor Red "The mailbox is not a Room Mailbox / Equipment Mailbox. RBA will only work with these. Exiting script.";
            exit;
        }
        if ($Mailbox.RecipientType -eq "Workspace") {
            $script:Workspace = $true;
        }
        Write-Host -ForegroundColor Green "The mailbox is valid for RBA will work with.";
    }

    Write-Host -ForegroundColor Yellow "For more information see https://learn.microsoft.com/en-us/powershell/module/exchange/get-mailbox?view=exchange-ps";
    Write-Host ;
}

# Validate that there are not delegate rules that will block RBA functionality
function ValidateInboxRules {
    Write-Host "Checking for Delegate Rules that will block RBA functionality."
    $rules = Get-InboxRule -mailbox $Identity -IncludeHidden
    if ($rules.Name -like "Delegate Rule*") {
        Write-Host -ForegroundColor Red "There is a user style Delegate Rule setup on this resource mailbox. This will block RBA functionality. Please remove the rule via Remove-InboxRule cmdlet and re-run this script."
        exit;
    }
    Write-Host -ForegroundColor Green "Delegate Rules check passes."
}

# Retrieve the CalendarProcessing information
function GetCalendarProcessing {
    Write-Host -NoNewline "Running : "; Write-Host -ForegroundColor Cyan "Get-CalendarProcessing -Identity $Identity"
    $script:RbaSettings = Get-CalendarProcessing -Identity $Identity

    # check we get a response
    if ($null -eq $RbaSettings) {
        Write-Host -ForegroundColor Red "Get-CalendarProcessing returned null.
                Make sure you Import-Module ExchangeOnlineManagement
                and  Connect-ExchangeOnline
                Exiting script.";
        exit;
    }

    Write-Host -ForegroundColor Yellow "For more information see
                https://learn.microsoft.com/en-us/powershell/module/exchange/set-calendarprocessing?view=exchange-ps";
    Write-Host ;

    $RbaSettings | Format-List
}


Review comment (suggestion):
2 quick questions:

1. Is `$rules.Name` localized? If so, `$rules.Name -like "Delegate Rule*"` would not work on non en-US systems.
2. Can we provide an output of the rules that were detected as problematic? Would be easier for customers to find out which of the rules should be removed.

Code after:
    # check we get a response
    if ($null -eq $Mailbox) {
        Write-Host -ForegroundColor Red "Get-Mailbox returned null. Make sure you Import-Module ExchangeOnlineManagement and  Connect-ExchangeOnline. Exiting script.";
        exit;
    } else {
        if ($Mailbox.RecipientTypeDetails -ne "RoomMailbox" -and $Mailbox.RecipientTypeDetails -ne "EquipmentMailbox") {
            Write-Host -ForegroundColor Red "The mailbox is not a Room Mailbox / Equipment Mailbox. RBA will only work with these. Exiting script.";
            exit;
        }
        if ($Mailbox.RecipientType -eq "Workspace") {
            $script:Workspace = $true;
        }
        Write-Host -ForegroundColor Green "The mailbox is valid for RBA will work with.";
    }

    Write-Host -ForegroundColor Yellow "For more information see https://learn.microsoft.com/en-us/powershell/module/exchange/get-mailbox?view=exchange-ps";
    Write-Host ;
}

# Validate that there are not delegate rules that will block RBA functionality
function ValidateInboxRules {
    Write-Host "Checking for Delegate Rules that will block RBA functionality..."
    Write-Host -NoNewline "Running : "; Write-Host -ForegroundColor Cyan "Get-InboxRule -mailbox $Identity -IncludeHidden"
    $rules = Get-InboxRule -mailbox $Identity -IncludeHidden
    # Note as far as I can tell "Delegate Rule <GUID>" is not localized.
    if ($rules.Name -like "Delegate Rule*") {
        Write-Host -ForegroundColor Red "Error: There is a user style Delegate Rule setup on this resource mailbox. This will block RBA functionality. Please remove the rule via Remove-InboxRule cmdlet and re-run this script."
        Write-Host -NoNewline "Rule to look into: "
        Write-Host -ForegroundColor Red  "$($rules.Name -like "Delegate Rule*")"
        Write-Host -ForegroundColor Red "Exiting script."
        exit;
    }
    Write-Host -ForegroundColor Green "Delegate Rules check passes."
}

# Retrieve the CalendarProcessing information
function GetCalendarProcessing {
    Write-Host -NoNewline "Running : "; Write-Host -ForegroundColor Cyan "Get-CalendarProcessing -Identity $Identity"
    $script:RbaSettings = Get-CalendarProcessing -Identity $Identity

    # check we get a response
    if ($null -eq $RbaSettings) {
        Write-Host -ForegroundColor Red "Get-CalendarProcessing returned null.
                Make sure you Import-Module ExchangeOnlineManagement
                and  Connect-ExchangeOnline
                Exiting script.";
        exit;
    }

    Write-Host -ForegroundColor Yellow "For more information see
                https://learn.microsoft.com/en-us/powershell/module/exchange/set-calendarprocessing?view=exchange-ps";