Scripts/Get-AzLogicAppResourceManagementUrl.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
param(
    [string][Parameter(Mandatory = $true)] $EnvironmentName,
    [string][parameter(Mandatory = $true)] $SubscriptionId,
    [string][parameter(Mandatory = $true)] $ResourceGroupName,
    [string][parameter(Mandatory = $true)] $LogicAppName,
    [string][Parameter(Mandatory = $true)] $ApiVersion,
    [string][Parameter(Mandatory = $true)][ValidateSet('enable','disable')] $Action
)


try{
    $resourceManagerUrl = ""   
    
    $environments = (Get-AzEnvironment).Name
    if($EnvironmentName -notin $environments){
        $supportedEnvironments = ""

        foreach($env in $environments){
            if($supportedEnvironments.Length -eq 0) {
                $supportedEnvironments += $env
            }
            else{
                $supportedEnvironments += ", " + $env
            }
        }

        Write-Error "Unrecognized environment specified. Supported values are: $supportedEnvironments"
    }

    $resourceManagerUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl
    
    $fullUrl = "$resourceManagerUrl" + "subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.Logic/workflows/$LogicAppName/$Action" + "?api-version=$ApiVersion"
   
    return $fullUrl
}
catch {
    Write-Warning "Failed to define the resource management endpoint."
    $ErrorMessage = $_.Exception.Message
    Write-Warning "Error: $ErrorMessage"
}