-1

Firstly Thanks for looking into this.

I've a requirement to update the inbound policy of an API managed by Azuremanagementservice from powershell. For this I have tried accessing the API from powershell unfortunately ended up at no progress.

What I am looking for via powershell a) Access API under AzuremanagementService b) Update the inbound operation policy

Thanks

2 Answers2

3

If you want to set policies by Azure PowerShell, try the code below(adding a root level inbound IP block policy for demo):

$newPolicy = '<policies>
                <inbound>
                    <ip-filter action="forbid">
                        <address-range from="192.168.0.1" to="192.168.0.2" />
                    </ip-filter>
                </inbound>
                <backend>
                    <forward-request />
                </backend>
                <outbound />
                <on-error />
             </policies>'

$apim_context = New-AzApiManagementContext -ResourceGroupName "<resource group name>" -ServiceName "<API management service name>"

Set-AzApiManagementPolicy -Context $apim_context  -Policy $newPolicy

Result: enter image description here

For more about Set-AzApiManagementPolicy operations, please see this reference doc.

UPDATE

If you want to modify the policy at API level, you need to use command below to get all ApiId:

Get-AzApiManagementApi -Context $apim_context | Select-Object Name,ApiId

enter image description here

I specify the ApiID as "echo-api":

Set-AzApiManagementPolicy -Context $apim_context  -Policy $newPolicy -ApiId 'echo-api'

Result: enter image description here

For more about set policy using PowerShell, please see here.

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Thanks for the response. I am looking to change for a specific API under that API Management Service. – user14846304 Jan 08 '21 at 20:44
  • @user14846304, I have uploaded my answer about how to modify policy on API level. Could you please lick the mark icon beside my answer to accept it if my post solves your issue ? – Stanley Gong Jan 10 '21 at 08:42