You can't define an alias for a variable (well, technically you can, as long as the variable isn't $null
, but then your alias would have the value of the variable at the time of the assignment).
What you can do is define a function that returns the value of $global:LastResult
and then an alias for that function:
function Get-LastResult { $global:LastResult }
New-Alias -Name last -Value Get-LastResult
However, I fail to see the advantage of an approach like this over directly using the variable $global:LastResult
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…