Skip to content

Remove-EnvironmentRoleAssignment

PowerApps: Removes an environment role assignment

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

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

    [string]$EnvironmentName,
    [string]$RoleId,
    [string]$ApiVersion
)

Process {
    try {
        ConnectPowerApps -PAFCredential $PACredential
        $args = @{ ErrorAction = 'Stop' }
        if ($PSBoundParameters.ContainsKey('EnvironmentName')) { $args.Add('EnvironmentName', $EnvironmentName) }
        if ($PSBoundParameters.ContainsKey('RoleId')) { $args.Add('RoleId', $RoleId) }
        if ($PSBoundParameters.ContainsKey('ApiVersion')) { $args.Add('ApiVersion', $ApiVersion) }
        Remove-AdminPowerAppEnvironmentRoleAssignment @args -ErrorAction Stop
        [PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; Status = "Success"; Message = "Environment role assignment removed" }
    }
    catch { throw }
    finally { DisconnectPowerApps }
}

PowerApps credentials

The environment name

The role assignment ID to remove

API version to call

An interactive directory of PowerShell scripts.