简体   繁体   English

在不使用向上箭头的情况下获取最后执行的命令为 output - PowerShell

[英]Getting the last executed command as output without using up arrow - PowerShell

I'm looking for a command to get the last executed command as output.我正在寻找一个命令来获取最后执行的命令为 output。 So far I found the automatic variable $$ , but it gives only the last word of the last executed command.到目前为止,我找到了自动变量$$ ,但它只给出了最后一个执行命令的最后一个字。 I'd like to avoid to use the up arrow of the keyboard (I need a command, not a key).我想避免使用键盘的向上箭头(我需要一个命令,而不是一个键)。

If the last command was part of your current session (vs. the last command at the end of your previous session), you can use the Get-History cmdlet:如果最后一个命令是当前 session 的一部分(与上一个会话结束时的最后一个命令相比),则可以使用Get-History cmdlet:

Get-History -Count 1

To get just the text of the command, you can pipe it through Select-Object :要获取命令的文本,您可以通过Select-Object pipe 它:

Get-History -Count 1 | Select-Object -ExpandProperty CommandLine

Get-History | select -last 1 | select -expand commandline

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可以获取PowerShell中执行的最后一个命令的计数吗? - Possible to get the count for the last command executed in PowerShell? 在Powershell中获取ADSI命令的输出 - Getting Output of ADSI Command in Powershell PowerShell 命令未使用 java 进程 class 执行。而所有其他命令工作正常 - PowerShell command not getting executed using java Process class. While all other commands are working fine 有没有一种方法可以捕获Powershell脚本执行的输出,而无需使用System.Management.Automation - Is there a way to capture powershell script executed output without using System.Management.Automation 获取powershell中最后一个被调用命令的参数? - Getting the arguments of the last invoked command in powershell? Powershell-从此Get-WmiObject命令获取输出(使用powershell获取内核数) - Powershell - get the output from this Get-WmiObject command (getting the number of cores using powershell) PowerShell 命令启动进程未在远程执行 - PowerShell command Start-Process not getting executed on remote 从PowerShell命令输出中获取特定部分 - Getting a specific part from a PowerShell command output 我正在使用 python 中的 powershell 命令获取一些数据,而在 Windows 中没有 cmd! 如何将此输出分配给字符串变量? - I am getting some data using powershell command from python without having a cmd in windows! how can i assigned this output to a string variable? 我正在尝试使用 -Command 选项执行一个包含 powershell 脚本的小字符串,但它没有被执行? 如何解决这个问题? - I am trying to execute a small String which contains a powershell script using -Command option but its not getting executed? how to resolve this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM