0

I have 3 values stored in the variables a,b and c. I want to find the greatest among them. The values of the variables are: a = 3, b = 6, and c = 2. The result should be the name of the variable that contains the maximum value—the text b.

1
  • 1
    what have you tried, what doesnt work? homework? Commented Nov 22, 2017 at 7:14

1 Answer 1

4
$a = 3
$b = 6
$c = 2

(Get-Variable -name a,b,c | Sort Value | Select -Last 1).Name

Result: b

This uses Get-Variable to return the variables $a, $b and $c, sorts the result by their value and then selects the last 1 from that sorted list (which as a result has the highest value) and returns it's Name property.

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.