Copy the PowerShell History to the Clipboard – Engineerer

Copy the PowerShell History to the Clipboard

The first command, works. The second command does not. I try out and at some point reach my destination (e.g. I was able to create a File Share in an Azure Storage Account through the AZ CLI to move files from my client to an Azure VM).

Because I’m a good engineer I tend to save the commands to a reusable script – or I want to blog about it.

The following command will get all the commands you used before it copies those nuggets to the clipboard. From there, you can paste it in VS Code or, if you want to stay plain, in a notepad. Erase the lines you don’t need anymore (where you were not concentrated😉) and there you have your script. Clean it up, add some variables, make it shiny et voilà.

Get-History | select commandline | clip