Private/Resolve-RBACScope.ps1

function Resolve-RBACScope {
    <#
    .SYNOPSIS
        Normalizes an Azure RBAC scope string.
    .DESCRIPTION
        Builds (or validates) an Azure resource scope from the supplied
        subscription, resource group, and explicit scope inputs. Internal helper.
    .OUTPUTS
        System.String
    #>

    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter()]
        [string]$Scope,

        [Parameter()]
        [string]$SubscriptionId,

        [Parameter()]
        [string]$ResourceGroupName
    )

    if ($Scope) {
        # Trim trailing slash for consistency.
        return $Scope.TrimEnd('/')
    }

    if ($SubscriptionId -and $ResourceGroupName) {
        return "/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName"
    }

    if ($SubscriptionId) {
        return "/subscriptions/$SubscriptionId"
    }

    throw 'Unable to resolve an RBAC scope. Provide -Scope, or -SubscriptionId (optionally with -ResourceGroupName).'
}