If you want to export all API operation inbound policy as .xml file to some folders by API Path just try the code below:
$apimName = "<your apim name>"
$apimSresourceGroup = "<your apim resource group>"
$exportPath = "d:/APIM/"
mkdir $exportPath
$apim_context = New-AzApiManagementContext -ResourceGroupName $apimSresourceGroup -ServiceName $apimName
$APIs = Get-AzApiManagementApi -Context $apim_context
foreach($API in $APIs){
$APIPath = $exportPath + $API.Name + '/'
mkdir $APIPath
$allOpers = Get-AzApiManagementOperation -Context $apim_context -ApiId $API.ApiId
foreach($oper in $allOpers){
$operPath = $APIPath +$oper.Method + '-' + $oper.Name
mkdir $operPath
$policy =[xml]@(Get-AzApiManagementPolicy -Context $apim_context -ApiId $oper.ApiId -OperationId $oper.OperationId)
$inBoundPolicyContent = $policy.policies.inbound.OuterXml
New-Item -Path $operPath -Name 'inbound.xml' -value $inBoundPolicyContent
}
}
Result
All API folders:
All operations of certain API:
Inbound policy of certain operation:
UPDATE:
If you also want to get API level inbound policy, try the code below:
$apimName = "<your apim name>"
$apimSresourceGroup = "<your apim resource group>"
$exportPath = "d:/APIM/"
mkdir $exportPath
$apim_context = New-AzApiManagementContext -ResourceGroupName $apimSresourceGroup -ServiceName $apimName
$APIs = Get-AzApiManagementApi -Context $apim_context
$APIs = Get-AzApiManagementApi -Context $apim_context
foreach($API in $APIs){
$APIPath = $exportPath + $API.Name + '/'
mkdir $APIPath
#save API level inbound policy
$API_policy =[xml]@(Get-AzApiManagementPolicy -Context $apim_context -ApiId $API.ApiId)
$inBoundPolicyContent = $API_policy.policies.inbound.OuterXml
New-Item -Path $APIPath -Name 'inbound.xml' -value $inBoundPolicyContent
#save API level inbound policy end
$allOpers = Get-AzApiManagementOperation -Context $apim_context -ApiId $API.ApiId
foreach($oper in $allOpers){
$operPath = $APIPath +$oper.Method + '-' + $oper.Name
mkdir $operPath
$policy =[xml]@(Get-AzApiManagementPolicy -Context $apim_context -ApiId $oper.ApiId -OperationId $oper.OperationId)
$inBoundPolicyContent = $policy.policies.inbound.OuterXml
New-Item -Path $operPath -Name 'inbound.xml' -value $inBoundPolicyContent
}
}
Just see the code under save API level inbound policy
.
Result:
Let me know if you have any further questions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…