比较4个变量(整数)并找到最大的数字

Mar*_*ood 0 powershell powershell-2.0

检索4个变量中具有最大值的变量的最短和最简单的方法是什么?

$a = 24224243243434
$b = 12312343432323
$c = 31231243434342
$d = 24343543432421
Run Code Online (Sandbox Code Playgroud)

Mat*_*sen 5

最大值:

PS C:\> ($a,$b,$c,$d|Measure-Object -Maximum).Maximum
31231243434342
Run Code Online (Sandbox Code Playgroud)

具有最大值的变量:

PS C:\> Get-Variable -Name a,b,c,d | Sort-Object -Property Value | Select -Last 1 -ExpandProperty Name
c
Run Code Online (Sandbox Code Playgroud)

完整的变量名(带有$):

PS C:\> '${0}' -f (Get-Variable -Name a,b,c,d | Sort-Object -Property Value | Select -Last 1 -ExpandProperty Name)
$c
Run Code Online (Sandbox Code Playgroud)