Scripts/Import-AzApiManagementOperationPolicy.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
param(
    [string][parameter(Mandatory = $true)] $ResourceGroupName,
    [string][parameter(Mandatory = $true)] $ServiceName,
    [string][parameter(Mandatory = $true)] $ApiId,
    [string][parameter(Mandatory = $true)] $OperationId,
    [string][parameter(Mandatory = $true)] $PolicyFilePath
)

$apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName

Write-Host "Updating policy of the operation '$OperationId' in API '$ApiId'"
$result = Set-AzApiManagementPolicy -Context $apimContext -ApiId $ApiId -OperationId $OperationId -PolicyFilePath $PolicyFilePath
if ($result) {
    Write-Host "Successfully updated the operation policy"
} else {
    Write-Error "Failed to update the operation policy, please check parameters"
}