0

Scenario: To List WebApps under a resourcegroup name.

Attempt Approach :

$WebAppApiVersion = "2015-08-01"
$MyResourceGroup = 'gurustorageRG'
Function saymyWebApps($ResourceGroupName)
 {
   Find-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceType $myResourceType -ApiVersion $WebAppApiVersion
 }

` saymyWebApps $MyResourceGroup

Output

Find-AzureRmResource : InvalidApiVersionParameter : The api-version '2015-08-01' is invalid. The supported versions are '2017-08-01,2 017-06-01,2017-05-10,2017-05-01,2017-03-01,2016-09-01,2016-07-01,2016-06-01,2016-02-01,2015-11-01,2015-01-01,2014-04-01-preview,2014- 04-01,2014-01-01,2013-03-01,2014-02-26,2014-04'. At line:24 char:5 + Find-AzureRmResource -ResourceGroupName $ResourceGroupName -Resou ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Find-AzureRmResource], ErrorResponseMessageException + FullyQualifiedErrorId : InvalidApiVersionParameter,Microsoft.Azure.Commands.ResourceMan

So, I picked 2017-08-01 from the listed error output for my webapiversion parameter and re-attempted, strangely it works listing the webapps created today or I assume at this point could list any app setup post 2017-08-01 ONLY.

Question 1: Does this mean, I would have to pull out available -apiversion and iterate through them to build entire webapp list under a resource group?

Attempted to see -apiversion but the output appears not complete or not matching with error thrown above as in Output block.

Snippet used to list the API Version:

Function GetAPIVersions()
 {
 ((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Web).ResourceTypes | Where-Object ResourceTypeName -eq sites).ApiVersions
}

GetAPIVersions

Output

2016-08-01

2016-03-01

2015-08-01-preview

2015-08-01

2015-07-01

2015-06-01

2015-05-01

2015-04-01

2015-02-01

2014-11-01

2014-06-01

2014-04-01-preview

2014-04-01

The above result is on successful execution of apiversion listing snippet.

Question 2: Why is the apiversion listing above not showing the api-versions list as shown in the error output of initial attempt approach?

4

1 回答 1

1

我们可以使用 fiddler 来捕捉它的执行Find-AzureRmResource,它使用List Resource API。我们可以发现该参数-ApiVersion代表list resource api version它与我们要查找的资源类型无关。

问题2:为什么上面的apiversion列表没有显示api-versions列表,如初始尝试方法的错误输出所示?

您提到列出Microsoft.Web的 API 版本,输出的 api 版本可用于操作 WebApp,例如创建或更新 azure webApp

所以-ApiVersion列表 API 版本是不同的。

总之:

如果我们要使用Find-AzureRmResource命令,我们需要使用错误信息中提到的 api 版本。

如果我们想查找操作特殊资源类型资源 api 版本,我们可以使用您提到的列表 api 方式。

于 2017-12-20T09:18:23.930 回答