Az.Powershell

Overview

The Az PowerShell module is a wrapper around the Azure REST API, meaning when you run a PowerShell cmdlet like Get-AzKeyVault or Get-AzResource, under the hood it makes authenticated HTTP calls to Azure's REST endpoints.

🔍 So, what endpoint does Az PowerShell use?

Each Az PowerShell cmdlet maps to a specific Azure Resource Manager (ARM) REST API endpoint, depending on the resource type and operation.

Here’s how it works:

PowerShell Cmdlet
Underlying Azure REST API Endpoint

Get-AzResource

GET https://management.azure.com/subscriptions/{subscriptionId}/resources?api-version=2021-04-01

Get-AzKeyVault

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{rg}/providers/Microsoft.KeyVault/vaults/{vaultName}?api-version=2023-02-01

New-AzRoleAssignment

PUT https://management.azure.com{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentGuid}?api-version=2022-04-01

Get-AzRoleAssignment

GET https://management.azure.com{scope}/providers/Microsoft.Authorization/roleAssignments?api-version=2022-04-01

The actual version used may vary depending on the cmdlet version and installed module.


🧠 How to see the exact REST call being made?

Use:

$DebugPreference = "Continue"
Get-AzResource

This will print HTTP request and response info to the console — including the full URI and headers.

Authentication

FOCI token required

Family-Of-Client-Ids - FOCI
# using TokenTactics
Invoke-RefreshToAzureManagementToken -Domain {domain} -refreshToken {refresh_token}

Connect-AzAccount

Connect-AzAccount -AccessToken $accesstoken -AccountId {account_id}

Enumeration

Azure Resource Management

After authenticating and connecting to your Azure account with Connect-AzAccount, you can perform various resource management tasks in Azure. Below is a command to enumerate resources using PowerShell.

Retrieve Azure Resources

To list all the resources within your Azure subscription, use the following command:

Get-AzResource | Format-Table

This command retrieves a list of all resources available under your account and displays them in a tabular format.

Further Reading

For more detailed guidance on managing Azure resources using PowerShell, please visit the official Azure PowerShell documentation.

Get Azure resource permission

$URI = 'https://management.azure.com/{ResourceId}/providers/Microsoft.Authorization/permissions?api-version=2022-04-01'
$RequestParams = @{ 
    Method = 'GET' 
    Uri = $URI 
    Headers = @{ 
        'Authorization' = "Bearer $access_token"    } 
} 
$Permissions = (Invoke-RestMethod @RequestParams).value 
$Permissions | fl *
function Get-AzPermissions {
    param (
        [Parameter(Mandatory = $true)]
        [string]$ResourceId,

        [Parameter(Mandatory = $true)]
        [string]$AccessToken
    )

    $URI = "https://management.azure.com/$ResourceId/providers/Microsoft.Authorization/permissions?api-version=2022-04-01"

    $RequestParams = @{ 
        Method  = 'GET'
        Uri     = $URI 
        Headers = @{ 
            'Authorization' = "Bearer $AccessToken"
        } 
    }

    $Permissions = (Invoke-RestMethod @RequestParams).value
    return $Permissions
}

Last updated