Executing PoSh line by line in VS Code

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

I’ve had to relearn this trick multiple times, so I decided to write a post. The simple answer is highlight code and press F8.

I’ve come to enjoy writing PoSh in VS Code, but I often end up writing a bunch of the code in a command window, trying out specific things. Often this is because I’m working in a specific folder. Sometimes I’ll get caught up in typing in the VS Code terminal, forgetting to edit the actual script.

Lots of sites have posts on this, but the simple thing is to pick a line and then click F8. The code will run in your terminal window, and you can see the results. Here’s an example for me.

2020-04-21 12_51_44-● $filter = _e__Documents_GitHub_MultiTena • Untitled-2 - Visual Studio Code

You can actually just put the cursor on a line and click F8. I’ve got a short gif that shows this.

poshvscode

The next time you want to work through a PoSh problem line by line, consider using VS Code and F8.

SQLNewBlogger

This is one of those things I’ve googled too many times. So I took 4-5 minutes to just type this up, grab a couple screenshots, and put this together.

It’s focused tightly on one thing, executing PoSh. I don’t need to explain more to show this piece of knowledge, and hopefully remember it in the future.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , , . Bookmark the permalink.

2 Responses to Executing PoSh line by line in VS Code

  1. Rod Falanga says:

    I didn’t know about this at all. More than that, it never occurred to know that you could run PoSh from within VS Code or any other editor, for that matter. And I’ve got to admit that pressing F8, after highlighting a line of code in VS Code, to run the code, isn’t obvious to me. But I’ll try to remember it.

    Thank you, Steve!

    Like

  2. way0utwest says:

    I wrote this because most of the time it’s not something I remember. Maybe now I will.

    Like

Comments are closed.