Skip to content

Set-PowerAppOwner

PowerApps Admin: Sets app owner

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

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

    [Parameter(Mandatory = $true)]
    [string]$AppName,

    [Parameter(Mandatory = $true)]
    [string]$EnvironmentName,

    [Parameter(Mandatory = $true)]
    [string]$Owner,

    [string]$ApiVersion
)

Process {
    try {
        ConnectPowerApps -PAFCredential $PACredential
        $args = @{ ErrorAction = 'Stop'; AppName = $AppName; EnvironmentName = $EnvironmentName; AppOwner = $Owner }
        if ($PSBoundParameters.ContainsKey('ApiVersion')) { $args.Add('ApiVersion', $ApiVersion) }
        $null = Set-AdminPowerAppOwner @args -ErrorAction Stop
        [PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; Status = "Success"; Message = "Owner set to '$Owner' for '$AppName'" }
    }
    catch { throw }
    finally { DisconnectPowerApps }
}

PowerApps credentials for authentication

The app identifier

The app's environment

New owner email or object ID

API version to call

An interactive directory of PowerShell scripts.