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

Code before:
        Write-Host -ForegroundColor Red "Consider configuring the properties below to process all requests.  (Default is null, True, null, False, null, True)."
        Write-Host
        Write-Host "`t RequestOutOfPolicy:            {$($RbaSettings.RequestOutOfPolicy)}"
        Write-Host "`t AllRequestOutOfPolicy:        "$RbaSettings.AllRequestOutOfPolicy
        Write-Host "`t BookInPolicy:                  {$($RbaSettings.BookInPolicy)}"
        Write-Host "`t AllBookInPolicy:              "$RbaSettings.AllBookInPolicy
        Write-Host "`t RequestInPolicy:               {$($RbaSettings.RequestInPolicy)}"
        Write-Host "`t AllRequestInPolicy:           "$RbaSettings.AllRequestInPolicy
        Write-Host -ForegroundColor Red "Exiting script."
        Stop-Transcript
        exit
    }
}

# Write out a list of Mailboxes
# We get CN from the cmdlet and want Display Name and Primary SMTP Address
function OutputMBList {
    param (
        [Parameter(Mandatory)]
        [string[]]$MBList
    )
    foreach ($User in $MBList) {
        # MS Support will error as we need the Organization to process from CN
        if ($Identity -like "*@*") {
            $Org = $Identity.Split('@')[1]
        }
        if ($null -ne $Org) {
            $User = Get-Mailbox -Identity $User -organization $Org
            Write-Host " `t `t [$($User.DisplayName)] -- $($User.PrimarySmtpAddress)"
        } else {
            $User = Get-Mailbox -Identity $User
            Write-Host " `t `t [$($User.DisplayName)] -- $($User.PrimarySmtpAddress)"
        }
    }
}

function InPolicyProcessing {
    # In-policy request processing
    Write-DashLineBoxColor @("  In-Policy request processing:") -Color Yellow

    if ($RbaSettings.BookInPolicy.Count -eq 0) {
        Write-Host "`t BookInPolicy:                     {$($RbaSettings.BookInPolicy)}"
    } else {
        Write-Host "`t BookInPolicy:                     These $($RbaSettings.BookInPolicy.count) accounts do not require the delegate approval."
        OutputMBList($RbaSettings.BookInPolicy)
    }
    Write-Host "`t AllBookInPolicy:                 "$RbaSettings.AllBookInPolicy
    Write-Host "`t RequestInPolicy:                  {$($RbaSettings.RequestInPolicy)}"
    Write-Host "`t AllRequestInPolicy:              "$RbaSettings.AllRequestInPolicy
    Write-Host


Review comment (bug):
Bug, need to set `$Org` to `$null` each time in the loop, otherwise `$Org` could be the last `$Identity` in the `$MBList`. 

You should be able to also do this: 
```
# No need for 'if ($Identity -like "*@*")' as split() doesn't return an error
$Org = $Identity.Split("@")[1]
if ($null -ne $Org) {...
```

This way `$Org` is always set correctly in the loop. 

Code after:
        Write-Host -ForegroundColor Red "Consider configuring the properties below to process all requests.  (Default is null, True, null, False, null, True)."
        Write-Host
        Write-Host "`t RequestOutOfPolicy:            {$($RbaSettings.RequestOutOfPolicy)}"
        Write-Host "`t AllRequestOutOfPolicy:        "$RbaSettings.AllRequestOutOfPolicy
        Write-Host "`t BookInPolicy:                  {$($RbaSettings.BookInPolicy)}"
        Write-Host "`t AllBookInPolicy:              "$RbaSettings.AllBookInPolicy
        Write-Host "`t RequestInPolicy:               {$($RbaSettings.RequestInPolicy)}"
        Write-Host "`t AllRequestInPolicy:           "$RbaSettings.AllRequestInPolicy
        Write-Host -ForegroundColor Red "Exiting script."
        Stop-Transcript
        exit
    }
}

# Write out a list of Mailboxes
# We get CN from the cmdlet and want Display Name and Primary SMTP Address
function OutputMBList {
    param (
        [Parameter(Mandatory)]
        [string[]]$MBList
    )
    foreach ($User in $MBList) {
        # MS Support will error as we need the Organization to process from CN
        $Org = $Identity.Split('@')[1]

        if ($null -ne $Org) {
            $User = Get-Mailbox -Identity $User -organization $Org
            Write-Host " `t `t [$($User.DisplayName)] -- $($User.PrimarySmtpAddress)"
        } else {
            $User = Get-Mailbox -Identity $User
            Write-Host " `t `t [$($User.DisplayName)] -- $($User.PrimarySmtpAddress)"
        }
    }
}

function InPolicyProcessing {
    # In-policy request processing
    Write-DashLineBoxColor @("  In-Policy request processing:") -Color Yellow

    if ($RbaSettings.BookInPolicy.Count -eq 0) {
        Write-Host "`t BookInPolicy:                     {$($RbaSettings.BookInPolicy)}"
    } else {
        Write-Host "`t BookInPolicy:                     These $($RbaSettings.BookInPolicy.count) accounts do not require the delegate approval."
        OutputMBList($RbaSettings.BookInPolicy)
    }
    Write-Host "`t AllBookInPolicy:                 "$RbaSettings.AllBookInPolicy
    Write-Host "`t RequestInPolicy:                  {$($RbaSettings.RequestInPolicy)}"
    Write-Host "`t AllRequestInPolicy:              "$RbaSettings.AllRequestInPolicy
    Write-Host

    if ($RbaSettings.AllBookInPolicy -eq $true) {