3 Visual Studio Code Intro
3 Visual Studio Code Intro
In this lab, we will use the Install-VSCode script from the PowerShell
Gallery to easily install VS Code with the PowerShell extension already
installed.
Note: If you are running your VMs from a macOS with the new M1 chip
(ARM architecture) you will need to download and install VSCode from
here instead of from the PowerShell gallery (select the Apple Silicon
option). Also, install the PowerShell extension and described here. Skip the
instructions about the PowerShell gallery below.
Search for vscode from the PowerShell Gallery and click on Install-
VSCode to learn how to install this helper script.
Install-VSCode
That was easy! Now you have a shortcut on your desktop to launch Visual
Studio Code. Let’s take it for a test drive.
Start VS Code and select “Open Folder” from the File Menu. Select the C:\
Users\IEUser\PowerShellForInfoSec folder. Now you should see the
class files in the Explorer as shown below.
Open the 1234.ps1 script by double clicking it from the Samples folder in
the Explorer.
When you run this script, you will see its output in the Terminal window on
the bottom right of VSCode.
Hover your mouse pointer over the $x variable (any one of them) and it will
show you the current value of x. At this point it the script, it has a value of 0.
Click the Step Over button on the debug menu bar to execute line three
and advance to line four.
Instead of hovering over a variable to see its value, you can also add it to
the watch list in the left menu, for quicker reference.
Click the plus sign in the watch window and enter $x as the variable name.
Now you can watch the value of x change as you step through the code
one line at a time.
The Step In and Step Out controls are helpful when your script calls a
function.
Note: Sometimes VS Code loses its mind. If you get an unexplainable error
as shown below, just close and reopen VS Code.
You should now be stopped at your breakpoint on line eight. Use the Step
Into button and notice where it takes you.
Continue to play with the VSCode code completion and debugging options
to get more familiar with this tool. I have found VS Code to be extremely
helpful for all my work with PowerShell and I hope that you will too!