rAJ
rAJ

Reputation: 1433

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.

Upvotes: 1

Views: 1268

Answers (1)

Jared Balfour
Jared Balfour

Reputation: 56

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

Upvotes: 1

Related Questions