Copy the PowerShell History to the Clipboard

I could elaborate a new script in VS Code. But sometimes the script will be tiny and this few commands can be executed directly in the console.

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

Author

  • Kai

    Hello you! My name is Kai Boschung and I live with my girl Dominique and our dog Nikita close to Bern, Switzerland.I work at Experts Inside and founded together with compadres the IoT consulting firm appery.

Leave a Reply