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

Code before:
        Write-Error "Exiting Script."
        Stop-Transcript
        exit
    }

    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."
        Stop-Transcript
        exit
    } elseif ($rules.Name -like "REDACTED-*") {
        Write-Host -ForegroundColor Yellow "Warning: No PII Access to MB so cannot check for Delegate Rules."
        Write-Host -ForegroundColor Yellow "To gain PII access, Mailbox is located on $($mailbox.Database) on server $($mailbox.ServerName)"
        if ($null -eq $rules.count) {
            Write-Host -ForegroundColor Yellow "Warning: One rule has been found, which is likely the default Junk Mail rule."
            Write-Host -ForegroundColor Yellow "Warning: You should verify that this is not a Delegate Rule setup on this resource mailbox. Delegate rules will block RBA functionality. Please remove the rule via Remove-InboxRule cmdlet and re-run this script."
        } elseif ($rules.count -gt 1) {
            Write-Host -ForegroundColor Red " --- Inbox Rules needs to be checked manually for any Delegate Rules. --"
            Write-Host -ForegroundColor Red "Warning: Multiple rules have been found on this resource mailbox. Only the Default Junk Mail rule is expected.  Depending on the rules setup, this may block RBA functionality."
            Write-Host -ForegroundColor Red "Warning: Please remove the rule(s) via Remove-InboxRule cmdlet and re-run this script."
        }
    } else {
        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."
        Stop-Transcript
        exit

Review comment (suggestion):
I think it would be better to include both statements here. 

```
$null -eq $rules.count -or $rules.count -eq 1
```

This way if `$rules.count` does equal 1 we catch it here.

Code after:
        Write-Error "Exiting Script."
        Stop-Transcript
        exit
    }

    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"
    [array]$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."
        Stop-Transcript
        exit
    } elseif ($rules.Name -like "REDACTED-*") {
        Write-Host -ForegroundColor Yellow "Warning: No PII Access to MB so cannot check for Delegate Rules."
        Write-Host -ForegroundColor Yellow "To gain PII access, Mailbox is located on $($mailbox.Database) on server $($mailbox.ServerName)"
        if ($null -eq $rules.count -or $rules.count -eq 1) {
            Write-Host -ForegroundColor Yellow "Warning: One rule has been found, which is likely the default Junk Mail rule."
            Write-Host -ForegroundColor Yellow "Warning: You should verify that this is not a Delegate Rule setup on this resource mailbox. Delegate rules will block RBA functionality. Please remove the rule via Remove-InboxRule cmdlet and re-run this script."
        } elseif ($rules.count -gt 1) {
            Write-Host -ForegroundColor Red " --- Inbox Rules needs to be checked manually for any Delegate Rules. --"
            Write-Host -ForegroundColor Red "Warning: Multiple rules have been found on this resource mailbox. Only the Default Junk Mail rule is expected.  Depending on the rules setup, this may block RBA functionality."
            Write-Host -ForegroundColor Red "Warning: Please remove the rule(s) via Remove-InboxRule cmdlet and re-run this script."
        }
    } else {
        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."
        Stop-Transcript
        exit