Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell – how to extract a value from Object[]

I’m trying to figure out how to grab the value associated with AzureWebJobsStorage variable from a Object[] in powershell. Here’s the logic so far:

 $azAppSettingsOutput = az functionapp config appsettings list --name somename --resource-group myResource --subscription subscription | ConvertFrom-Json
Write-Output $azAppSettingsOutput.GetType().name
Write-Output $azAppSettingsOutput | Get-Member
Write-Output $azAppSettingsOutput.name

This is the output I see:

PS C:\Users\me> .\test.ps1
Object[]

   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
name        NoteProperty string name=APPINSIGHTS_INSTRUMENTATIONKEY
slotSetting NoteProperty bool slotSetting=False
value       NoteProperty string value=asdfasdf-asdf-asdf-asdf-asdf-asdf

APPINSIGHTS_INSTRUMENTATIONKEY
AzureWebJobsStorage
FUNCTIONS_EXTENSION_VERSION
FUNCTIONS_WORKER_RUNTIME
WEBSITE_RUN_FROM_PACKAGE
StorageTableName

PS C:\Users\me\>

I know I can loop through like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

foreach($setting in $azAppSettingsOutput) {
    Write-Output $setting.name
    $value = $setting.value

And then I can add an if statement to check if the name matches "AzureWebJobsStorage" but just wondering if there’s a simpler way.

Thanks.

>Solution :

Use the Where-Object cmdlet to filter your data:

$azAppSettingsOutput |Where-Object name -eq 'AzureWebJobsStorage'

This will filter out any objects except for those where the name property equals "AzureWebJobsStorage"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading