为了增强用户体验,PowerShell 引入了 PSReadLine 模块。PSReadLine 提供了先进的命令行编辑和历史记录功能,使得在命令行环境中工作更加高效和便捷。 什么是 PSReadLine 模块 PSReadLine 是一个开源的 PowerShell 模块,旨在提供一个更好的命令行编辑器。 安装和加载 PSReadLine 模块 在 Windows 10 和更高版本中,PSReadLine 模块通常是预装的。 模块: powershell Import-Module PSReadLine PSReadLine 的基本配置 PSReadLine 提供了多种配置选项,可以通过 Set-PSReadLineOption \PSReadLine\ConsoleHost_history.txt" 搜索历史命令 PSReadLine 允许用户快速搜索历史命令。
Delete((Get-PSReadLineOption).HistorySavePath)Remove-Item "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine ConsoleHost_history.txt" -ForceGet-ChildItem "C:\Users\*\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine Get-PSReadLineOption -EA Stop|Select -Exp HistorySavePath}catch{}}else{"$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine
SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{57E5A8BB-41EB-4F09-B332-B535C5954A28} /f (2)安装PSReadLine 通过安装-模块命令安装: Install-Module -Name PSReadLine 弹出提示: NuGet provider is required to continue PowerShellGet Help (default is "Y"): 再次需要输入侧Y进行安装 如果需要实现一键安装,可以先安装的NuGet,再安装PSReadLine,完整命令如下: Install-PackageProvider (3)使用 所有的PowerShell命令将会保存在固定位置:%appdata%\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt 如果系统是Powershell v3或Powershell v4,可通过命令行安装PSReadLine,这样就能记录后续系统所有的Powershell命令。
安裝 PSReadLine 模組 優化 PowerShell 環境的利器,不過只能在 PowerShell 7 執行: Install-Module PSReadLine -AllowPrerelease GetDirectoryName($PROFILE))if (-not (Test-Path -Path $PROFILE -PathType Leaf)) { New-Item $PROFILE -Force} 啟用 PSReadLine 並啟用超強自動完成功能 你可以直接將我的 PROFILE_PSReadLine.ps1 內容加入到 PROFILE 啟動設定檔中! gist.githubusercontent.com/doggy8088/d3f3925452e2d7b923d01142f755d2ae/raw/aabe600ed2adccb43165228b8c8ced6e88ac9fc0/$PROFILE_PSReadLine.ps1
该功能由PSReadline模块提供,虽然从用户体验角度很有帮助,但也可能被黑客利用。 为解决此问题,PSReadline模块v2.0.4+版本引入敏感词过滤机制,当命令行包含以下关键词时将跳过历史记录(详情参见):PasswordAsplaintextTokenApikeySecretPowerShell v7.0.11+默认搭载支持此功能的PSReadline版本,而Windows PowerShell 5.1预装的PSReadline v2.0.0不支持该功能(但可手动更新)。
安装PSReadLinePSReadLine:github.com/PowerShell/… PSReadLine模块取代了 PowerShell 版本 3 及更高版本的命令行编辑体验。 上面是github里的介绍,但其实我们主要用到PSReadLine的功能就是自动保存历史记录,敲过一个命令后,后面只需要敲前几个字母就能提示出命令,按【→】键就可以自动补全命令语法着色 PSReadLine 4.1 安装PSReadLine以管理员身份运行Windows Terminal,执行下面命令:Install-Module PSReadLine -Force复制代码没有以管理员身份运行Windows -AllowPrerelease来安装PSReadLine? # 先安装PowerShellGetInstall-Module -Name PowerShellGet -Force# 然后再这条命令安装PSReadLineInstall-Module PSReadLine
DRCheck-LocalAdminHash是一款新型PowerShell脚本,可针对多台主机验证密码哈希是否为有效的管理员凭证,并能够从该凭证具有管理员权限的所有系统中提取每个配置文件下的所有PowerShell PSReadline :https://github.com/dafthack/Check-LocalAdminHash历史记录收集需求在最近的一次评估中,我需要收集网络中所有系统的PowerShell控制台历史记录文件(PSReadline PSReadline控制台历史记录本质上是PowerShell版本的bash历史记录。 模块获取域中所有计算机列表利用Kevin Robertson的Invoke-TheHash工具进行哈希传递认证通过Invoke-WMIExec连接每个主机并执行编码的PowerShell命令发现系统所有配置文件中的PSReadline testdomain.local -Username PossibleAdminUser -PasswordHash E62830DAED8DBEA4ACD0B99D682946BB -AllSystems渗透所有PSReadline
在 Windows 上,我们也可以打造类似体验,利用 PowerShell 7 + Oh My Posh + PSReadLine + posh-git,并让 VS Code 终端完美适配。 安装完之后到设置如果看不到PowerShell 7,那么手动添加一个配置文件三、安装 Oh My Posh、posh-git 和 PSReadLine在 PowerShell 7 中执行:# 更新 PowerShellGetInstall-Module JanDeDobbeleer.OhMyPosh -s winget# 安装 posh-git(Git 自动补全)Install-Module posh-git -Scope CurrentUser -Force# 安装 PSReadLine (增强自动补全)Install-Module PSReadLine四、修改 PowerShell 配置文件PowerShell 配置文件路径:$PROFILE可以用 VS Code 打开:code $PROFILE
本文将介绍如何使用 PSReadLine 、oh-my-posh 和 posh-git 这三个模块来为 PowerShell 带来类似于 Mac 上的 oh my zsh 的体验,包括语法高亮、错误提示 查看已安装的模块 Get-InstalledModule 安装 PSReadLine PSReadLine 提供了语法高亮、错误提示、多行编辑、键绑定、历史记录搜索等功能: Install-Module PSReadLine 安装 posh-git posh-git 可以在 PowerShell 中显示 Git 状态信息,并提供 Git 命令的自动补全: Install-Module posh-git -------------- Import Modules BEGIN ------------------------------- # 引入 ps-read-line Import-Module PSReadLine 总结 本文介绍了如何使用 PSReadLine 、oh-my-posh 和 posh-git 这三个模块来为 PowerShell 打造个性化的命令行体验,包括语法高亮、错误提示、多行编辑、键盘绑定、自动补全
因为最终我们是通过 Windows Terminal 启动 Powershell 插件安装 使用 PowerShell, 执行下面的命令分别安装 Posh-Git 和 Oh-My-Posh: # PSReadline - 实现类似 ZSH 那样的命令补全 Install-Module -Name PSReadLine -Scope CurrentUser # posh-git - Git 插件 Install-Module Import Modules ======================= Import-Module posh-git Import-Module oh-my-posh Import-Module PSReadLine 也可以另外开启一个 Terminal 输入`Get-PoshThemes` 来直接查看所有主题 Set-Theme marcduiker # ========================= PSReadLine
Install-Module posh-git -Scope CurrentUser Install-Module oh-my-posh -Scope CurrentUser 如果在PS Core上运行此功能,请确保已经安装PSReadLine 的2.0.0-beta1版本 Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
winget install Microsoft.PowerShell也可以去官网下载powershell ,目前官网推荐的版本是 7.x安装 PowerShell 扩展模块Install-Module PSReadLine ,为了方便使用还自定义一个名为 'cc' 的函数别名function cc { claude --dangerously-skip-permissions @args}# ---------- PSReadLine
>%userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt" 2>$null HistorySavePath 2>$null clear-history cmd.exe /c "del %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline >%userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt" 2>$null HistorySavePath 2>$null;clear-history;cmd.exe /c "del %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline
Microsoft.PowerShell.Management Get-PSSession Cmdlet Microsoft.PowerShell.Core Get-PSReadlineOption Cmdlet PSReadLine Get-PSReadlineKeyHandler Cmdlet PSReadLine Get-PSProvider Cmdlet Microsoft.PowerShell.Management Get-PSHostProcessInfo Microsoft.PowerShell.Core Set-PSSessionConfiguration Cmdlet Microsoft.PowerShell.Core Set-PSReadlineOption Cmdlet PSReadLine Set-PSReadlineKeyHandler Cmdlet PSReadLine Set-PSDebug Cmdlet Microsoft.PowerShell.Core Set-PSBreakpoint Publish-Script Function PowerShellGet Publish-Module Function PowerShellGet PSConsoleHostReadline Function PSReadLine
POSH_THEMES_PATH\montys.omp.json | Invoke-Expression Import-Module posh-git # 引入 posh-git Import-Module PSReadLine 首先在 PowerShell 执行以下命令安装插件: Install-Module -Name PowerShellGet -Force Install-Module PSReadLine -AllowPrerelease -Force 然后修改前面的配置文件 Microsoft.PowerShell_profile.ps1,在末尾追加以下内容: Import-Module PSReadLine # 历史命令联想 #
如果使用的是PowerShell Core,请安装PSReadline: Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck
powershell命令历史记录,如果命令用不起,可以查看powershell的txt %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline \ConsoleHost_history.txt %appdata%\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt 注册表
如图所示,分别输入命令Install-Module -Name PSReadLine Install-Module oh-my-posh 。
exe 运行该文件,找到一个历史文件: 下载该文件: download C:\Users\legacyy\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine
Microsoft\Windows\Recent,c:\windows\system32\config,c:\users\*\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine