Private/Initialize-RBACContext.ps1

function Initialize-RBACContext {
    <#
    .SYNOPSIS
        Builds a probe context from a public cmdlet's bound parameters.
    .DESCRIPTION
        Internal. Picks the standard context/run-as parameters out of a caller's
        $PSBoundParameters and forwards them to Resolve-RBACContext, so every
        public cmdlet exposes an identical run-as surface without duplicating the
        plumbing. Returns the ambient context when no run-as parameter is present.
    .OUTPUTS
        PSCustomObject (PSAutoRBAC.Context)
    #>

    [CmdletBinding()]
    [OutputType([psobject])]
    param(
        [Parameter(Mandatory)]
        [hashtable]$BoundParameters
    )

    $passthrough = @{}
    foreach ($name in 'TenantId', 'RunAsCredential', 'RunAsServicePrincipal', 'RunAsTenantId',
        'RunAsManagedIdentity', 'RunAsManagedIdentityClientId') {
        if ($BoundParameters.ContainsKey($name)) { $passthrough[$name] = $BoundParameters[$name] }
    }
    Write-PSFMessage -Level Debug -Message "Initializing probe context from $($passthrough.Count) run-as parameter(s)." -Tag 'PSAutoRBAC', 'Context'
    Resolve-RBACContext @passthrough
}