Windows PowerShell-如何查看命令历史记录日期/时间


12

我想列出Windows中输入的命令PowerShell及其各自的时间戳。我该如何使用Get-History命令?

另外,如果这样做不可行,请向我展示一种方法,以检查通过urls(network)哪个时间戳已访问哪个时间戳CMD

还请考虑我已经重新启动计算机。

Answers:


17

在Windows 10上,默认情况下,PowerShell 5随附PS扩展名PsReadline。获取以下内容,以查看完整的命令历史记录。

C:\ Users \用户名\ AppData \ Roaming \ Microsoft \ Windows \ PowerShell \ PSReadline \ ConsoleHost_history.txt

要使其在Windows 7上可用,必须确保已安装最新的Framework和PowerShell 5。然后,您可以安装PsReadline模块。

我只是在Windows 7(64)机器上做的:

(执行策略:remotesigned)

Install-Module PSReadLine(被要求安装NuGet-anycpu.exe,并回答是)。

导入模块PsReadLine

您的历史记录现在将存储在上述文件中(已验证)

运行Get-PSReadlineKeyHandler获取 PSReadline键绑定的列表。


该目录C:\Users\DavidPostill\AppData\Roaming\Microsoft\Windows\PowerShell对我而言不存在...
DavidPostill

如果您正在运行PS的早期版本,则为true。谢谢(你的)信息。
Dan St-G

嗯 我正在运行5.0版-您正在运行哪个版本?
DavidPostill

看起来PSReadlineWindows 7实现中没有PowewrShell 5.0。
DavidPostill

大卫,您说得对,对不起您的误导。帖子已编辑。
Dan St-G

3

据我所知,一旦关闭PowerShell控制台,所有的历史记录和日志都会被丢弃。

您可以签出类似以下内容的内容:为PowerShell提供持久的命令历史记录

当然,这不会检索您已经完成的任何事情,只会从安装时开始记录日志。

编辑:PowerShell 5.0似乎已经实现了一个持久的历史记录,即使重新启动后也可以通过常规方式访问。


3

Powershell历史记录保存在文件ConsoleHost_history.txt中,以查找执行以下PS命令的文件位置 :-(Get-PSReadlineOption).HistorySavePath


0

对于PowerShell 5.1和PowerShell Core,我将其添加到我的代码中$PROFILE以使其更容易记住:

function Get-PSReadLineHistory
{
    Get-Content (Get-PSReadlineOption).HistorySavePath
}

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.