Variable value parsing

I have a variable with below value, if we see this variable value the words “qualityGateStatus”, “bugs” , “vulnerabilities” and “codeSmells” are repeated multiple times with their corresponding values.
Now i want to get the last instances of these words with their corresponding values. how can i get this done? please help.

$var1 = @{qualityGateStatus=OK; bugs=5; vulnerabilities=8; codeSmells=15} @{qualityGateStatus=failed; bugs=1; vulnerabilities=1; codeSmells=5} @{qualityGateStatus=OK; bugs=3; vulnerabilities=6; codeSmells=7}

if i print the values from the above variable value, i should get the values “OK”, “3”, “6” and “7”

As below are the last values in the above variable value, the output should be like…

qualityGateStatus is OK
bugs are 3
vulnerabilities are 6
codeSmells are 7

Bit of weird question because you’ve not provided valid code but assuming $var1 is an array of hashtables, just select the last element:

$var1 = (@{qualityGateStatus='OK'; bugs=5; vulnerabilities=8; codeSmells=15},
         @{qualityGateStatus='failed'; bugs=1; vulnerabilities=1; codeSmells=5},
         @{qualityGateStatus='OK'; bugs=3; vulnerabilities=6; codeSmells=7})

$var1[-1]

I suspect there’s a better way to do what you’re doing though.

Just as a final point, please can you use the pre-formatted text button </> when posting code. It makes it much easier to read.

thank you matt, with $var1[-1] i am getting the complete last line “@{qualityGateStatus=‘OK’; bugs=3; vulnerabilities=6; codeSmells=7}”, but i want the individual words values from this line. output should be like below:

qualityGateStatus is OK
bugs are 3
vulnerabilities are 6
codeSmells are 7

$var1 = (@{qualityGateStatus='OK'; bugs=5; vulnerabilities=8; codeSmells=15},
         @{qualityGateStatus='failed'; bugs=1; vulnerabilities=1; codeSmells=5},
         @{qualityGateStatus='OK'; bugs=3; vulnerabilities=6; codeSmells=7})

$result = @"
qualityGateStatus is $($var1[-1].qualityGateStatus)
bugs are $($var1[-1].bugs)
vulnerabilities are $($var1[-1].vulnerabilties)
codeSmells are $($var1[-1].codeSmells)
"@

$result

Or even easier:

$var1 | select-object -last 1