Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
232 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...