EDIT
Adding this edit at the top because it is clearly the best answer, I was not aware the Azure CLI could output json, thanks mclayton.
# Some alternatives using "-o json"
az resource list -g $RESOURCE_NAME -o json | ConvertFrom-Json |
Where-Object {$_.Type -match 'serverFarms'} | Select -Expand Name
# OR
$resGroup = az resource list -g $RESOURCE_NAME -o json | ConvertFrom-Json
$resGroup.where({$_.Type -match 'serverFarms'}).Name
I propose this solution to your problem, of course, as in yesterday's comments Ash recommended using the Az Module which is definetly recommended. An alternative to parse this output which will be reusable for future cases, is to convert it to an object which can be easily manipulated (this is what TheMadTechnician proposed which in my opinion is much better than using a particular regex to get the result you want).
Note: I'm splitting on '\r\n' because I'm using a string copy pasted from your question. In your case, simply pipping the result of az resource... to Select-String should work fine.
$output = @'
Name ResourceGroup Location Type
---------------------- --------------- ---------- ---------------------------------
jf-aa-ext-app-12345 jfFuncs eastus microsoft.insights/components
omstorage jfFuncs eastus Microsoft.Storage/storageAccounts
jf-aa-ext-app-12345 jfFuncs eastus Microsoft.Web/serverFarms
jf-aa-ext-app-12345 jfFuncs eastus Microsoft.Web/sites
'@ -split '\r\n' | Select-String -Pattern '^[^-]'
$parsedOutput = $output -replace '\s{2,}',',' | ConvertFrom-Csv
Output:
PS /> $parsedOutput
Name ResourceGroup Location Type
---- ------------- -------- ----
jf-aa-ext-app-12345 jfFuncs eastus microsoft.insights/components
omstorage jfFuncs eastus Microsoft.Storage/storageAccounts
jf-aa-ext-app-12345 jfFuncs eastus Microsoft.Web/serverFarms
jf-aa-ext-app-12345 jfFuncs eastus Microsoft.Web/sites
PS /> $parsedOutput | Get-Member -MemberType NoteProperty
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Location NoteProperty string Location=eastus
Name NoteProperty string Name=jf-aa-ext-app-12345
ResourceGroup NoteProperty string ResourceGroup=jfFuncs
Type NoteProperty string Type=microsoft.insights/components
The result you want:
PS /> $parsedOutput.where({$_.Type -match 'serverFarms'}).Name
jf-aa-ext-app-12345
^(\S*).*\bserverFarms\bgive the results you need?azhas an--output jsonoption that would be easier to parse withConvertFrom-Json- no regex required. From there, you can justwhere-objectyour way to victory...