- Use Azure Bastion as a jump host for RDP and SSH - Tue, Apr 18 2023
- Azure Virtual Desktop: Getting started - Fri, Apr 14 2023
- Understanding Azure service accounts - Fri, Mar 31 2023
Microsoft Most Valuable Professional (MVP) Adam Driscoll is one of my PowerShell heroes for the following reasons:
- He is a brilliant software developer.
- He gives freely to the Microsoft technology community.
- He is an astute businessman.
In 2010 Adam created PowerGUI VSX, a free Visual Studio add-on that gave Visual Studio its first PowerShell language support. Fast-forward to 2019, and alongside much critical acclaim, Adam's product portfolio has broadened to include:
- PowerShell Tools for Visual Studio: This freeware Visual Studio add-on provides the core PowerShell language support minus the PowerGUI integration.
- PowerShell Pro Tools: This retail product greatly extends the PowerShell Tools functionality.
- PowerShell Universal Dashboard: This retail product simplifies the development and maintenance of web-based, interactive dashboards. For instance, in my spare time I'm working on a PowerShell Universal Dashboard project that provides an easy-to-use front-end for PowerShell Just Enough Administration (JEA).
As a PowerShell administrative scripter, you may be thinking, "Why should I care about Visual Studio?" In response I want to remind you that Visual Studio (a) is available in a free Community Edition and (b) offers us a first-class PowerShell development experience when you use Adam's tools.
Installing PowerShell Pro Tools
In Visual Studio, open the Extensions menu and select Manage Extensions. As shown in the following screenshot, you'll find Adam's PowerShell Tools for Visual Studio in the Visual Studio Marketplace.
The PowerShell Pro Tools are bundled with the PowerShell Tools extension; you needn't install anything else. All functionality is unlocked for three weeks, after which you must purchase a license if you want to continue using the Pro Tools.
An important point: The PowerShell Tools for Visual Studio extension is free; look at the feature comparison to spot the differences. In a nutshell, the free extension gives you your basic PowerShell language support, including:
- Syntax highlighting
- IntelliSense
- PSScriptAnalyzer integration
- Snippets
- Local and remote debugging
As you'll learn momentarily, PowerShell Pro Tools extends on the basic extension's functionality by providing:
- C# to PowerShell code conversion
- Build events and package bundling
- Code obfuscation
- WinForm and Windows Presentation Foundation (WPF) designers
To license PowerShell Pro Tools in Visual Studio, click Help > About PowerShell Pro Tools and enter your product key.
Only PowerShell Pro Tools (the paid product) is available for Visual Studio Code. Locate the extension in the Visual Studio Marketplace, as shown in the next figure.
To license PowerShell Pro Tools in VSCode, open the command palette, type PowerShell Pro Tools: Install License Key, paste in your key, and away you go!
Finally, install PowerShell Pro Tools as an ordinary module by running the following PowerShellGet command:
Install-Module -Name 'PowerShellProTools'
And then run the following command to install your license:
Install-PoshProToolsLicense -Path 'C:\license.txt'
Okay, enough with the preliminaries—let's test out this extension! In the interest of time and whitespace, I will use Visual Studio 2019 as my testing environment from now on.
Configuring PowerShell Pro Tools
Your first stop in Visual Studio is to open Tools > Options, navigate to PowerShell Tools > General, and set your extension preferences. In particular, here is where you can optionally disable the PSScriptAnalyzer integration if it annoys you or otherwise gives you trouble.
Next, in the Options dialog, navigate to Environment > Fonts and Colors and optionally customize the syntax highlighting for the many PowerShell options. You can see this interface in the next screenshot.
Writing and running PowerShell code
When you install PowerShell Tools for Visual Studio, you can create PowerShell modules or script projects by using the included templates. Here, let me show you the New Project dialog in Visual Studio 2019:
Creating a new PowerShell project in Visual Studio 2019
Click View > Other Windows > PowerShell Interactive Window to open a Visual Studio-anchored PowerShell console host. Pretty cool!
Check out the next figure to observe that PowerShell Tools for Visual Studio gives us syntax highlighting and IntelliSense for PowerShell just like we'd expect for C#:
As far as running your code is concerned, you can use the standard Visual Studio run and debug commands (F5, Ctrl+F5, and so on). You can always right-click selected code and choose Run Selected Code from the shortcut menu to run just that line in the PowerShell Interactive window.
Finally, PowerShell Pro Tools gives you some excellent project item templates, including:
- PowerShell script
- PowerShell test
- PowerShell script data file
- PowerShell WPF window
- PowerShell script module
- PowerShell form
- PowerShell service
Next let's examine a few of the PowerShell Pro Tools-only product features.
Performing code conversions
The PowerShell Pro Tools code conversion feature serves developers who need to refactor their existing C# code to PowerShell or vice versa. Here's how you use it:
- In your original source file, copy your C# or PowerShell source code to the clipboard.
- In your target file, right-click and choose either Paste as PowerShell or Paste as C# from the shortcut menu.
Here's what the simple "Hello world" C#-to-PowerShell process looks like on my system:
I imagine that for some businesses, the code conversion feature alone is enough to justify the license cost.
User interface design
Although the idea of writing a graphical PowerShell application may seem illogical to you at first blush, it really isn't. For example, a PowerShell-based GUI may be just what you need to use the same codebase to give:
- help desk personnel the ability to carry out tasks without knowing PowerShell
- administrators the ability to use the source code for their own purposes
Earlier in this review, I mentioned that I plan to use Adam's PowerShell Universal Dashboard framework to build an administrator-friendly front-end to PowerShell JEA. I can do the same thing with the GUI designer in PowerShell Pro Tools.
To get started, add a PowerShell WPF Window item to your Visual Studio project. As you can see in the next screenshot, PowerShell Pro Tools does most of the "code behind" work for you. Drag and drop on your GUI control surface, set some properties, wire up your events, package the application as an executable, and you're finished. Pretty impressive stuff, for sure.
Wrap-up
There's a lot more to PowerShell Pro Tools than I have the "whitespace" to tell you about. Here are some pointers to get you familiarized with the toolset's other major features:
- PowerShell code obfuscation and packaging
- Application bundling/packaging
- Unit testing
- Pre- and post-build pipeline events
As of April 2019, Adam charges $59.99 USD for a PowerShell Pro Tools single-user license. That single code will activate the toolset in Visual Studio, VSCode, and your PowerShell console host.
Subscribe to 4sysops newsletter!
After testing this software, I've added it to my list of "must-install" tools for my Visual Studio work. My homework assignment is to kick the tires on VSCode next. Let us know what you think of PowerShell Pro Tools in the comments, and I'll catch you next time!
This is an awesome add on. I'm testing it now to see how it compares to sapien powershell studio.
I purchased the Pro version. Copying PS code which worked just fine when posted in a Terminal window failed. Save your money, it's not worth it.