PowerShell Get-History

PowerShell Get-History

One command that I love to use in PowerShell is Get-History. It retrieves all of the commands that you have run in this session. You can use the id and count parameters to pick a single command or a number of commands including and prior to the id

e.g. Get-History -id 10 -count 5 gets command lines 6 through to 10 inclusive.

You can then also combine that with Set-Clipboard to copy commands to the clipboard so you can paste them into something else. Note that you can use clip.exe but that doesn’t support UTF-8 whereas Set-Clipboard does

(Get-History -id 10 -count 5).commandline | Set-Clipboard

Now those commands are ready to just Paste wherever you like 🙂

Related posts: