当您运行命令“New-AzureRmApiManagementApi”时,您只需创建一个 api,该 api 不会添加到产品中。您需要运行命令“Add-AzureRmApiManagementApiToProduct”将 api 添加到产品中。我的脚本如下
$ResourceGroupName=""
$sku=""
$name=""
$Location=""
$Organization=""
$AdminEmail=""
$apiName=" #the name of the web API."
$url="" #the URL of the web service that exposes the API.
$path="" #the web API path, which is the last part of the API's public URL and corresponds to the Web API URL suffix field in the admin portal.
#login azure
Connect-AzureRmAccount
#create api management instance with required parameters
New-AzureRmApiManagement -ResourceGroupName $ResourceGroupName -Name $name -Sku $sku -Location $Location -Organization $Organization -AdminEmail $AdminEmail
$ApiMgmtContext =New-AzureRmApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $name
#create api
$api = New-AzureRmApiManagementApi -Context $ApiMgmtContext -Name $apiName -ServiceUrl $url -Protocols @("http", "https") -Path $path
#run the command if you do not know product id
Get-AzureRmApiManagementProduct -Context $ApiMgmtContext
#add api to product
Add-AzApiManagementApiToProduct -Context $ApiMgmtContext -ProductId "" -ApiId $api.ApiId
Azure API管理powershell命令的更多细节,请参考文档