Search code examples
azurepowershellazure-resource-group

Get the value of the app service plan using Powershell


I am trying to get the only name value of the app service plans using Powershell.

Query :

Get-AzResource -ResourceGroupName "entaddinqagrouptwm" -ResourceType Microsoft.Web/serverfarms | ft

The Output is :

Name                       ResourceGroupName  ResourceType              Location
----                       -----------------  ------------              --------
ntaddinqaapptwmeastusplan1 entaddinqagrouptwm Microsoft.Web/serverFarms eastus
ntaddinqaapptwmeastusplan2 entaddinqagrouptwm Microsoft.Web/serverFarms eastus

My Code :

$resourceHash = Get-AzResource -ResourceGroupName "entaddinqagrouptwm" -ResourceType Microsoft.Web/serverfarms | ft
Write-Host "Apps : " $resourceHash.GetValue(0)

The result I am getting :

Apps :  Microsoft.PowerShell.Commands.Internal.Format.FormatStartData

The result I want :

ntaddinqaapptwmeastusplan1
ntaddinqaapptwmeastusplan2

So that I can use for each loop on the result and perform operation one by one on each app plan.


Solution

  • I believe the code below is what you need. No need to "format list". You just need to properly select the property on the $resourceHash object.

        $resourceHash = Get-AzResource -ResourceGroupName "entaddinqagrouptwm" -ResourceType Microsoft.Web/serverfarms
        Write-Host "Apps : " $resourceHash.Name