Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.21k stars 3.82k forks source link

Invoke−AzRestMethod −Method Get Not Supported for any version #26097

Open RandyDotCom opened 5 days ago

RandyDotCom commented 5 days ago

Description

From CoPilot

$managedIdentity = Get-AzUserAssignedIdentity -ResourceGroupName -Name

$associatedResources = Invoke-AzRestMethod -Method Get -Path "/subscriptions/$($managedIdentity.SubscriptionId)/resourceGroups/$($managedIdentity.ResourceGroupName)/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$($managedIdentity.Name)/listAssociatedResources?api-version=2021-09-30-preview"

I tried all API Versions 2023-07-31-PREVIEW 2023-01-31 2022-01-31-PREVIEW 2021-09-30-PREVIEW 2018-11-30 2015-08-31-PREVIEW

All Versions reported that Method "Get" was unsupported. Az cli worked, so I am assuming it was not permissions.

Issue script & Debug output

Not applicable / Protected environment

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.5
PSEdition                      Core
GitCommitId                    7.4.5
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                       
---------- -------    ---------- ----                        
Script     3.0.0                 Az.Accounts                 
Script     1.2.1                 Az.ManagedServiceIdentity   
Script     7.1.0                 Az.Resources

Error output

Not applicable
mortenlerudjordet commented 2 days ago

That API version does not show up in the documentation, so maybe use one that is supported?

https://learn.microsoft.com/en-us/rest/api/managedidentity/user-assigned-identities?view=rest-managedidentity-2023-01-31

Also your URL is not correct for calling the api, this works just fine on my end.

$versionURL = "https://management.azure.com/subscriptions/$($subId)/resourceGroups/$($rgName)/providers/Microsoft.ManagedIdentity/userAssignedIdentities?api-version=2023-01-31"
$result = Invoke-AzRestMethod -Method Get -Uri $versionURL