
有多种命令清理powershell历史记录
[System.IO.File]::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\*_history.txt" | Remove-Item -Force以上在Server2016/2019/2022/2025测试没问题
下面这个在Server2008R2~2025测试没问题
$path=if($PSVersionTable.PSVersion.Major -ge3){try{Get-PSReadLineOption -EA Stop|Select -Exp HistorySavePath}catch{}}else{"$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt"};if($path){Remove-Item $path -Force -EA 0}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。