Scripts/Import-AzApiManagementProductPolicy.ps1

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

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

Write-Host "Updating policy of product '$ProductId'"
$result = Set-AzApiManagementPolicy -Context $apimContext -ProductId $ProductId -PolicyFilePath $PolicyFilePath
if ($result) {
    Write-Host "Successfully updated the product policy"
} else {
    Write-Error "Failed to update the product policy"
}