0
votes

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?

1

1 Answers

1
votes

We could use fiddler to catch the execution of Find-AzureRmResource,it uses the List Resource API. We could find that the parameter -ApiVersion stands for list resource api version. It is not related to what resource type we want to find.

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

You mentioned list the API Version for Microsoft.Web , the output api version could be used for operating WebApp,for instance, create or update azure webApp.

So -ApiVersion and list API version are different.

In summary:

if we want to use Find-AzureRmResource command,we need to use the api versions that mentioned in the error info.

If we want to find the operation sepicial resource type resource api version, we could use you mentioned list api way.