0

How do i loop through an array of values into a format of Key, value pairs?

$a= Search-AzGraph -Query "Resources | project tags"

$a.tags[0]

Environment : Non-Production

Application : Openshift

AppOwner    : AzureOncall

End result should look like

Key                      Value

Environment              Non-Production

Application              openshift
6
  • 2
    $a.tags[0] -replace ':', '=' | ConvertFrom-StringData Commented Feb 17, 2021 at 12:20
  • What is $a? Is it an array of PSCustomObjects? Commented Feb 17, 2021 at 20:18
  • @theo after i use your command , results look as below 'Name Value ---- ----- @{environment production; dataclassification=x; application=x; created_by=x; appowner=x; rnlcode=x}' Commented May 6, 2021 at 9:16
  • Then could you please tell us what $a.tags[0].GetType().FullName reveals, so we know what we're dealing with? Commented May 6, 2021 at 9:31
  • @theo $a.tags[0].GetType().FullName System.Management.Automation.PSCustomObject Commented May 7, 2021 at 10:20

1 Answer 1

2

Building on Theos Comment,you can use below

ConvertFrom-StringData -StringData $StringData -Delimiter ':'
Sign up to request clarification or add additional context in comments.

1 Comment

Note that -Delimiter requires PS 7.0 at least.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.