Skip to content

Get-PowerAppRoleAssignment

PowerApps: Retrieves PowerApp role assignments

#Requires -Version 5.1
#Requires -Modules Microsoft.PowerApps.PowerShell

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [pscredential]$PACredential,

    [string]$AppName,
    [string]$EnvironmentName,
    [string]$PrincipalObjectId,
    [string]$ApiVersion,

    [ValidateSet('*', 'PrincipalDisplayName', 'RoleName', 'RoleId', 'PrincipalEmail', 'AppName', 'EnvironmentName', 'PrincipalObjectId', 'PrincipalType', 'RoleType', 'Internal')]
    [string[]]$Properties = @('PrincipalDisplayName', 'RoleName', 'RoleId', 'PrincipalEmail', 'AppName', 'EnvironmentName')
)

Process {
    try {
        ConnectPowerApps4Creators -PAFCredential $PACredential

        $getArgs = @{ ErrorAction = 'Stop' }
        if ($PSBoundParameters.ContainsKey('ApiVersion')) { $getArgs.Add('ApiVersion', $ApiVersion) }
        if ($PSBoundParameters.ContainsKey('AppName')) { $getArgs.Add('AppName', $AppName) }
        if ($PSBoundParameters.ContainsKey('EnvironmentName')) { $getArgs.Add('EnvironmentName', $EnvironmentName) }
        if ($PSBoundParameters.ContainsKey('PrincipalObjectId')) { $getArgs.Add('PrincipalObjectId', $PrincipalObjectId) }

        $result = Get-PowerAppRoleAssignment @getArgs -ErrorAction Stop | Select-Object $Properties
        if ($null -ne $result) { foreach ($item in $result) { $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force } }
    }
    catch { throw }
    finally { DisconnectPowerApps4Creators }
}

PowerApps credentials for authentication

The app identifier

The app's environment

Object ID of a user or group to filter by

API version to call

Properties to retrieve. Use * for all.

An interactive directory of PowerShell scripts.