powershell

PowerShell: Is there an automatic variable for the last execution result?


I'm looking for a feature comparable to Python interactive shell's "_" variable. In PowerShell I want something like this:

> Get-Something # this returns an object and display it to the output.
# Now I want to assign that object to some variable
> $anObj = ???

Solution

  • No there is not automatic variable like that.

    You have to do:

    $output = Get-Something
    $output
    $anObj = $output
    

    to get the behaviour