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

前端 未结 10 1898
名媛妹妹
名媛妹妹 2021-02-05 00:29

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

> Get-Something # this returns          


        
10条回答
  •  猫巷女王i
    2021-02-05 01:08

    Last option that requires most work but IMO gives you what you ask for: create proxy that will overwrite Out-Default (that is always called implicitly at the end of pipeline, if you don't out-* to something else).

    Jeffrey Snover gave presentation on it during one of PowerShell Deep Dives (I reckon it was the first one) - you can find scripts he used (including above mentioned out-default) on Dmitry Sotnikov blog. You can also watch video from it to understand whole concept.

提交回复
热议问题