Skip to content

New-Environment

PowerApps: Creates an environment

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

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

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

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

    [ValidateSet('Production', 'Sandbox', 'Trial')]
    [string]$EnvironmentSku = 'Production',

    [string]$ApiVersion
)

Process {
    try {
        ConnectPowerApps -PAFCredential $PACredential
        $args = @{ ErrorAction = 'Stop'; DisplayName = $DisplayName; LocationName = $LocationName; EnvironmentSku = $EnvironmentSku }
        if ($PSBoundParameters.ContainsKey('ApiVersion')) { $args.Add('ApiVersion', $ApiVersion) }
        $result = New-AdminPowerAppEnvironment @args -ErrorAction Stop | Select-Object *
        if ($null -ne $result) { $result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force }
    }
    catch { throw }
    finally { DisconnectPowerApps }
}

PowerApps credentials

Display name for the environment

Geographic location for the environment

SKU type: Production, Sandbox, Trial

API version to call

An interactive directory of PowerShell scripts.