Skip to content

Instantly share code, notes, and snippets.

@nanoDBA
Last active January 25, 2023 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanoDBA/48f2cd1eab1e4433a97bd106e0dac08d to your computer and use it in GitHub Desktop.
Save nanoDBA/48f2cd1eab1e4433a97bd106e0dac08d to your computer and use it in GitHub Desktop.
Loop through PSReadline histories for all user profiles and copy them to the clipboard
### Get Command Line History for all users
# source: https://gist.github.com/nanoDBA/48f2cd1eab1e4433a97bd106e0dac08d
$dirs = (Get-ChildItem -Directory (Split-Path $env:USERPROFILE)).FullName | Sort-Object
$allHistories = foreach($profileDir in $dirs){
Write-Output "### $profileDir"
$historySavePath = "$profileDir\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt"
if(!(Test-Path ($historySavePath) )) {
Write-Output "### $historySavePath does not exist"
}
else {
Write-Output "# PSReadline $historySavePath "
Get-Content $historySavePath
}
$([environment]::NewLine)
}
($allHistories).trim() | Set-Clipboard # Copy Command Line History for all users to the clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment