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 ;
}

# 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
}

function EvaluateCalProcessing {

    if ($RbaSettings.AutomateProcessing -ne "AutoAccept") {
        Write-Host -ForegroundColor Red "AutomateProcessing is not set to AutoAccept. RBA will not work as configured. "
        Write-Host -ForegroundColor Red "AutomateProcessing is set to"$RbaSettings.AutomateProcessing
        Write-Host -ForegroundColor Yellow "Use 'Set-CalendarProcessing -Identity $Identity -AutomateProcessing AutoAccept' to set AutomateProcessing to AutoAccept."
        Write-Host -ForegroundColor Red "Exiting script."
        exit
    } else {
        Write-Host -ForegroundColor Green "AutomateProcessing is set to AutoAccept. RBA will analyze the meeting request."
    }

Review comment (suggestion):
Is it possible that there is more than one rule returned? If yes, I'd recommend doing a `foreach` here.

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";