1

In PowerShell I'm working on a script and can't solve this:

$GROUPA = 'A', 'B', 'C', 'D'
$GROUPB = 'E', 'F', 'G', 'H'

$SELECT = 'GROUPA'

write-output $$SELECT (or something)

I have a view arrays, and than a script thats output one of the array names. And I want to output that array, but can't find how to do that with powershell.

1
  • 1
    Why is everyone so hell-bent on trying to define variables on the fly? Please take a step back and describe the actual problem you're trying to solve instead of what you perceive as the solution. Commented May 3, 2017 at 9:34

2 Answers 2

1

Your $SELECT is just a string, instead you probably want to assign it to the $GROUPA variable:

$SELECT = $GROUPA    
write-output $SELECT

Or, if you wan't a to resolve a variable using a string, use the Get-Variable cmdlet:

$SELECT = Get-Variable 'GROUPA'
Sign up to request clarification or add additional context in comments.

4 Comments

yes, but how? because $SELECT = $+'GROUPA' output $GROUPA
If you just write $SELECT it will output the array.
$SELECT2 = Get-Variable $SELECT is working thank you
Your welcome. Ansgar is write, you should think about whether this is the right approach for your solution. However, please consider to accept the answer.
0

This may help you (even if it's old topic)

$A=1
$B=2
$C=3
$D=4
$E=11
$F=12
$G=13
$H=14
$GROUPA = 'A', 'B', 'C', 'D'
$GROUPB = 'E', 'F', 'G', 'H'
$SELECT=$GROUPB
$myval1 = (Get-Variable $SELECT[0]).Value
$myval2 = (Get-Variable $SELECT[1]).Value
$myval3 = (Get-Variable $SELECT[2]).Value
$myval4 = (Get-Variable $SELECT[3]).Value

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.