azurepowershellazure-functions

How can I get the list of actions supported by a resource for use with Invoke-AzResourceAction PowersShell command?


Consider the following PowerShell command taken from here:

Get-AzResource -Name RESOURCE-NAME | Invoke-AzResourceAction -Action host/default/listkeys -Force

I'm trying to figure out how to action host/default/listkeys was determined.

The help information for Invoke-AzResourceAction says:

DESCRIPTION

The Invoke-AzResourceAction cmdlet invokes an action on a specified Azure resource. To get a list of supported actions, use the Azure Resource Explorer tool.

So, I went to the Azure Resource Explorer tool (see below). But the operations clearly don't match the -Action above.

How can I figure out actions myself to use with Invoke-AzResourceAction?

enter image description here


Solution

  • How can I figure out actions myself to use with Invoke-AzResourceAction?

    az-resource-invoke-action is the equivalent Azure CLI command of Invoke-AzResourceAction.

    The documentation says (emphasis mine):

    A list of possible actions corresponding to a resource can be found at https://docs.microsoft.com/rest/api/. All POST requests are actions that can be invoked and are specified at the end of the URI path.

    For instance, to List Function Keys, the request URI is

    https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}/listkeys?api-version=2024-04-01

    So if I understand correctly the corresponding action is listkeys (see the end of the URL: .../listkeys?...).

    Running the correspondent Invoke-AzResourceAction command:

    Invoke-AzResourceAction -Action "listkeys" `
                            -ResourceId "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}" `
                            -ApiVersion "2024-04-01"
    

    Regarding the Azure Resource Explorer, it seems the actions can be found in the name property of the json displayed in the screenshot (the ones that end with /action). Format seems to be the following:

    /{resource-type}/{action-name}/action