Visual Studio Code as a PowerShell Integrated Scripting Environment

I know what you’re thinking. “Why use Visual Studio Code instead of the PowerShell ISE?” Well, if you’re using Mac OS or Linux, you don’t have the option to use the PowerShell ISE natively. And that’s a problem if you want to take advantage of the cross-platform capabilities of PowerShell Core. In this article, I’ll show you how to use Visual Studio Code (free!) to perform the key functions of the PowerShell ISE, namely:

  • Simultaneously view code and execute it in the PoSh terminal
  • Execute code on a selection or line-by-line basis (F8)
  • Syntax highlighting (for people who are easily bored like me)

Installing Visual Studio Code

The best way to install most things is with a package manager. This would be something like apt-get or yum for Linux distros, homebrew for Mac OS, and Chocolatey for Windows. Or you could go old school and download it here.

Installing the PowerShell Extension

Go to the Extensions button (looks like a busted up square) or View > Extensions.

If the PowerShell extension doesn’t show up under the bombastic “RECOMMENDED” heading, just search for it in the “Search Extensions” field. Then install it.

Integrating the PowerShell Terminal

Open up a PowerShell script of your choice. Then in the menu, go to View > Integrated Terminal. You should see the following.

If you don’t see the PS prompt Make sure you select “TERMINAL” and “PowerShell Integrated” from the drop-down menu.

Running Only Selected Code

In the PowerShell ISE, you can select a block of text and hit F8, and the ISE runs only that code. Or you can position your cursor at the end of a line and hit F8, and the ISE runs only the code on that line. Next we’ll enable the exact same behavior in Visual Studio Code.

Go To File > Preferences > Keyboard Shortcut

In the text entry field at the top, type “runsel”. You should see two items:

  • “Run Selection” with a keybinding to F8
  • “Run Selected Text In Active Terminal” with no keybinding

This is not what we want because it will not run the selected text in the PowerShell terminal.┬áIt will run the selection in the “OUTPUT” section, but not in the terminal. Obviously, that’s not the normal behavior of the PowerShell ISE. Let’s fix it.

Right-click the “Run Selection” item and select “Remove keybinding”

Right-click the “Run Selected Text in Active Terminal” item and select “Add Keybinding”

Depress the F8 key (or whatever you want to use) then hit Enter.

Testing It Out

Go back to your code and select a block of code. Hit F8 and watch the magic!

That’s what I’m talking about!

But… as of this writing, there’s an issue with this that’s being tracked on the vscode-powershell GitHub repo, and it’s this: multi-line input in the integrated console doesn’t work. That means you can’t select a function block, hit F8, and have it work. It will throw ugly errors in your face.

Windows Server Core Full Configuration with PowerShell

How to Configure Server Core with Active Directory Services, DNS, and DHCP Using Nothing But PowerShell

Windows Server 2012 offers two installation options: Server Core or “Server with a GUI”. This begs the question: Why would you want to install Server Core instead of the GUI? One reason may be that you have limited physical hardware resources and want to keep the footprint as small as possible.

Recently I needed to build a domain controller, DHCP, and DNS server for a branch office. This office has a Riverbed Steelhead WAN optimization appliance which runs a nested VMware ESXi hypervisor. The appliance has limited memory and disk space, so I needed to keep the installation as small as possible (Incidentally, if I only needed DNS and DHCP, I would have just installed RedHat Enterprise Linux, but having the server be an Active Directory domain controller was also a requirement.)

I’m going to show you step-by-step how I configured Active Directory Services, DNS, and DHCP on a Windows Server 2012 Server Core installation. Continue reading

How to Recover a Lost Form in Internet Explorer or Firefox Without Any Add-Ons or Pre-Installed Utilities

You’ve got a sinking feeling in your gut. You were working on a text document in your web browser when suddenly you accidentally clicked the wrong button or hit the wrong key combination, and POOF, it’s all gone. I will show you how to get it all back.

Necessity is the mother of invention. If you’ve been looking for ways to recover a lost form in your web browser, you’ve likely come across a lot of unhelpful information. Certainly if you had been using one of those utilities that automatically save your work for you, you wouldn’t be searching for a how-to on getting your lost data back. This article is for you.

To recover your lost form data, you will need:

HxD Hex Editor
– Notepad or your favorite text editor
– A little patience

Step 1.
Download and install the HxD hex editor from the link above and load it up.

Step 2.
In the menu bar, select Extras -> Open RAM…

Step 3.
Here you will see a list of all running processes. If you lost your form data in Internet Explorer, select iexplore.exe. Or if you were using Firefox, select firefox.exe. Now hit OK.

Step 4.
The hex editor will load the appropriate portion of your system’s RAM (random-access memory) that contains your lost form data. In the menu bar, select Search -> Find.

Step 5.
In the Find box, enter a portion of text from the form that you lost. Here you may have to go through a little trial-and-error. If you enter just one word, you may be sorting through a lot of data to find the proverbial needle in the haystack. If you enter too many words, you may skip right over some useful form data. I recommend starting with just two words that you know were in your lost form. Each time the hex editor finds a match, it will stop. Just hit F3 on your keyboard to continue searching.

Step 6.
Once you find what looks like a portion of your lost form data, copy it into your text editor. Select the text on the right-hand side, then click Edit -> Copy on the menu bar. Now paste the text into notepad or your favorite text editor.

Step 7.
Go back to Step 5 and continue the process until you have recovered your entire form.

Sometimes you will find almost 100% of the lost data sitting there untouched, but you will still need a little patience to piece together any missing pieces. And yes, you will probably have to retype a few words at the end. But doing it the way I have suggested will take much less time than retyping the entire form by hand.