skip to Main Content

I am trying get the properties of an Azure Disk Resource. When I run the command in my subscription

$R=Get-AzResource -Name <ResourceName>

It provides a list of properties given here I am specifically interested getting the Properties PSobject. However running the following command:

$R.Properties -eq $null

does returns true. When I look at this resource from Azure Portal (Same user principal as in Powershell command) in Json format I am given a selection of schemas to choose from and lots of properties are provided. Below is a sample:

"properties": {
        "osType": "Linux",
        "hyperVGeneration": "V2",
        "supportsHibernation": true,
        "supportedCapabilities": {
            "acceleratedNetwork": true,
            "architecture": "x64"
        },
        "creationData": {
            "createOption": "FromImage",
            "imageReference": {
                "id": "xxx"
            }
        },
        "diskSizeGB": 30,
        "diskIOPSReadWrite": 500,
        "diskMBpsReadWrite": 60,
        "encryption": {
            "type": "EncryptionAtRestWithPlatformKey"
        },
        "networkAccessPolicy": "AllowAll",
        "publicNetworkAccess": "Enabled",
        "timeCreated": "2023-01-09T13:38:24.500223+00:00",
        "provisioningState": "Succeeded",
        "diskState": "Attached",
        "diskSizeBytes": 32213303296,
        "uniqueId": "xxx"

What is the proper command to get this information using PowerShell?

2

Answers


  1. You should set the ExpandProperties switch

    https://learn.microsoft.com/en-us/powershell/module/az.resources/get-azresource?view=azps-9.3.0#-expandproperties

    $resourceWithProperties = Get-AzResource -Name <ResourceName> -ExpandProperties
    

    You can the access the properties with

    $resourceWithProperties.Properties
    
    Login or Signup to reply.
  2. You can get all properties using -ExapandProperties command and Alternative way of getting all properties is by using below commands:

    Connect-AzAccount
    
    $disk = Get-AzResource -ResourceId "/subscriptions/<subscriptionId>/resourceGroups/<Rg name>/providers/Microsoft.Compute/disks/<Diskname>"  
    $disk.Properties | Format-List *
    

    Output:

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search