Let’s face it, you look down at your taskbar and you have 5 PowerShell/PowerCLI sessions open. You open each session and scroll through the commands. Each session was used for something unique and you have hundreds of commands run in each.

If you are like me, you’ll have a few that are for testing some API calls, some for working out the kinks in a script you are writing, and some are just plain administration. But many of them you figured out what you needed to, but you didn’t write it down or copy it out of the session.

I’ve thrown together a fast and easy function to dump your session history into a text file of your choice.

The reason I threw this together was because Alan Renouf (@RenoufA) pinged me and told me the newest version of PowerCLI had dropped and it was now in the Microsoft PowerShell Gallery! WOOHOO! More on that in another post… Back to the story!  I wanted to update as quickly as possible but I had all of these PowerCLI sessions opened. I decided to quickly do a Get-History and dump the .Commandline values into a text file. (using the .Commandline shows the entire command run rather than truncating it). Once I’d done this I figured others might be in the same boat so I threw this together.

You will see that all you need to do is type:

You can get the latest version from my Github repository here. The initial version you will find below, but it will not get updated like the one in the repository will.

 

Written by

Brian

Brian Graf is a Sr. Technical Marketing Manager for VMware Cloud on AWS at VMware. He has also worked on ESXi Lifecycle, PowerCLI Automation and been the Product Manager for vSphere DRS and HA. Brian is co-author of the PowerCLI Deep Dive 2nd edition book and a Microsoft MVP.

You May Also Like to Read

Bitnami