0

I have functions and each function returns an return code. I want to output the following:

function ReturnCode
-------- ----------
 wrapkey         255
 mapkey          233
 delkey            0

I tried:

$Outarray = @()

$Outarray += $_.SetProperty("WrapKey") | select "WrapKey", ReturnCode 
$Outarray += $_.SetProperty("MapKey") | select "MapKey", ReturnCode

$Outarray | Format-Table

How can I do this?

1 Answer 1

2

You're looking for calculated properties, the syntax of which is as follows:

@{Name='Name of resulting property';Expression={<# actual value calculation goes here#>}}

So for the result you want (one object per SetProperty() call), that would be something like:

$_.SetProperty('WrapKey') | Select-Object @{Name='Function';Expression={'WrapKey'}},@{Name='ReturnCode';Expression={$_}}

And then repeat for MapKey and DelKey. Since only the property names vary, you can throw them into a loop:

$OutputCodes = foreach($Name in 'WrapKey','MapKey','DelKey'){
    $_ | Select-Object @{Name='Function';Expression={$Name}},@{Name='ReturnCode';Expression={$_.SetProperty($Name)}}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.