How To Copy Command History to the clipboard in PowerShell

Copying Command History

Source: Copying Command History – Power Tips – PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources

You can copy your entire command history to the clipboard:

(Get-History).CommandLine | clip.exe 

This technique uses automatic unrolling introduced in PowerShell 3.0. To use it in PowerShell 2.0, you would have to manually expand the CommandLine property like this:

Get-History | Select-Object -ExpandProperty commandline | clip.exe 

To copy only the last five commands, simply add the -Count parameter to Get-History:

(Get-History -Count 5).CommandLine | clip.exe