PowerShell Sessions and VS Code

If you do any amount of PowerShell scripting you have most likely heard about Visual Studio Code. This is a free cross-platform light-weight editor from Microsoft. VS Code supports multiple languages and is extensible. I’ve tried different versions since it was first released but never found a reason to jump from the PowerShell ISE. For my purposes the ISE works just fine plus I’ve customized it so much that it would be hard to abandon. But there is a new version of VS Code that is at least making it more tempting.

Continue reading

PowerShell Deep Dive Treasure

Without a doubt the PowerShell Deep Dive conference was one of the best meetings I’ve ever attended and I wanted to share one tidbit I came away with that I find immensely useful and never knew. During one of Bruce Payette’s talks he tossed out, practically as an aside, a reference to searching command line history with the # character. What!!???

I never heard of this and it is very slick. From the command prompt (either the console or ISE) enter the # character followed by whatever part of a previous command you remember. It does not have to be the start of the command, it can be any part of it. Then press TAB. PowerShell will search your history buffer and return the first match. If there are multiple matches you can keep pressing TAB to cycle through them. Awesome! The beauty for me is that it just brings the command back to the prompt so you can edit it.

Thank you Bruce!

Get Variable Definition

Last week a question came across my email about how to find out where a variable came from. I thought this was a great question because I’ve run into this scenario as well. I see a variable but don’t recall what command I typed to create it. What I need is an easy way to find the command so I made a tool. Continue reading

Convert History to Script

Whenever I teach or speak about PowerShell, a recurring mantra is that there is no difference between running a PowerShell script and executing commands interactively in the shell, except that it saves you typing. You can create a PowerShell script by simply copying and pasting commands from the shell into a .PS1 text file. This means you can develop and test your script as you write it. But copying and pasting can be a pain. One alternative I have is a script to take your PowerShell history and turn it into a script file. Continue reading