The values of the variables are: a = 3, b = 6, and c = 2 d=6 The result should be the name of the variable that contains the maximum value— the text b&d i.e the result of maximum value.
1 Answer
$a = 3
$b = 6
$c = 2
$d = 6
$Variables = Get-Variable -name a,b,c,d
$Variables | Where { $_.Value -eq ($Variables | Measure-Object Value -Maximum).Maximum } | Select Name
Use Measure-Object to get the largest (maximum) value from the set of variables, then use Where-Object to filter the collection of variables to those with that maximum value and return their names via Select-Object.