PoshTip #47 – Save a Command into PowerShell History

Everybody knows that when you type a PowerShell command, this command will be automatically saved into history. Then, you can get the history with the following command:

But sometimes you may want to save a command into history without executing it for later execution or just for information.

You also can save a comment into history. Of course, you can do something like that:

Now, I can check the history:

It works but you will get a lot of error messages into the PowerShell console. So the best practice is to use the # character before your comment or command:

It can be useful or just a gadget! It’s up to you!

 

Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 196 Articles
I work as a System Engineer, based in Switzerland with a primary focus on Microsoft technologies. I have 7 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSA: Windows Server 2012" and "Administering & Deploying SCCM" certified.