Are you still using the old Quest / Dell PowerGUI tool to author your PowerShell scripts and modules? If so, you may want to consider getting off the PowerGUI train, and hopping onto the Visual Studio 2015 or PowerShell Integrated Scripting Editor (ISE) train! By doing so, you will improve your PowerShell script & module authoring experience, and you’ll have a whole host of tools at your fingertips, that will increase your productivity!!
As always, make sure that you’re running the latest version of the Windows Management Framework (WMF) package, to ensure that you’ve got the latest version of PowerShell installed! Also, if you’re not a developer, and lean more towards the IT pro side of things, don’t be intimidated by Visual Studio. It’s a beast, I get that, but learn to tame the beast, and harness its power, and you will certainly become more productive, you will be able to collaborate on projects more effectively as a team, and you will have many more tools available in your toolbox!
Authoring PowerShell in Visual Studio 2015
Visual Studio 2015 RTM’d just recently, back on July 20th, with great fanfare! There are tons of new features, including full support for Microsoft PowerShell MVP Adam Driscoll’s baby known as PoshTools! For any new projects you’re kicking off, or even existing projects you’ve got in-process, make sure you give the PoshTools extension a whirl!
Not too long ago, I made a video on MSDN Channel 9 that talks about the benefits of PoshTools, so start by watching that!
Why You Should Use Visual Studio PoshTools!
You should definitely use PoshTools for your PowerShell automation projects, most importantly because Visual Studio supports the notion of project files! Project files help you keep track of all the individual script files that make up your overall project! If you already have an existing Visual Studio solution, and need to add deployment or configuration management scripts to your solution, you can simply add a new PowerShell project to the solution!
Visual Studio also makes for a great PowerShell authoring experience, because it includes full support for Intellisense! You also benefit from the incredible Visual Studio support for keyboard shortcuts!! If you’re using source control for your PowerShell projects (which you should be!!), then you automatically get the Team Explorer window, which integrates with services like Visual Studio Online (VSO), GitHub, and others!
By leveraging the Visual Studio framework, you automatically get the ability to rely on other add-ons, such as the Markdown editor included with the Web Essentials VS extension, authored by Mads Kristensen (Microsoft). You can search through the VSIX Gallery for more Visual Studio extensions!
Visual Studio PoshTools Limitations
While the overall PowerShell authoring experience in Visual Studio is excellent, thanks to PoshTools, you might run into some challenges!
First of all, the Visual Studio debugger can hang sometimes, for unknown reasons. Secondly, the debugger occasionally loses track of which line a particular piece of code is running on, so it might throw you off. Thankfully, this bug is easily worked around by restarting Visual Studio! Third of all, the PowerShell Interactive Window doesn’t always format objects the way you’d expect, so it’s a bit more complicated to get the desired output, compared to using the PowerShell ISE. This is mainly an issue for interactive work, but any time you’re writing and testing code, there is a combination of automated and interactive work!
Authoring PowerShell in ISE
Microsoft has made great strides in the PowerShell Integrated Script Editor (ISE) since its inception in PowerShell version 2.0! Although it could still use quite a bit of work, Intellisense support has been improved dramatically! PowerShell Desired State Configuration (DSC) even supports Intellisense for authoring configuration documents and DSC resource instances inside them.
Why You Should Use ISE!
If you’re running a combination of interactive PowerShell commands, and script authoring — which is pretty typical — the PowerShell ISE will be more forgiving, compared to Visual Studio PoshTools. Objects emitted to the output stream will be formatted correctly, and the debugging experience is a bit more reliable, even though it could still use some work as well.
Syntax highlighting is one of the essential features of any development environment, and the PowerShell ISE has a great set of default colors to differentiate commands from parameters, parameter values, and other syntactical constructs. Both the PowerShell ISE and Visual Studio PoshTools extension win big points in this area!
If you install Jason Shirk’s (Microsoft employee, PowerShell core team) TabExpansion++ module, you can add support for custom “argument completers!” These custom argument completers are really cool, because you can add support for tab-completion of PowerShell cmdlet parameter values, that aren’t even part of your own module!
If you’re authoring Service Management Automation (SMA) or Azure Automation Runbooks, which are simply PowerShell Workflows (as of today), you will benefit from a new ISE add-on developed by the Azure Automation team. This add-on helps you to write and test your Runbooks locally, and then upload them to Azure Automation directly from the ISE, without having to pull up the Microsoft Azure management portal!
Here’s a list of other PowerShell ISE add-ons that you can use to help enhance your productivity!
— Trevor Sullivan (@pcgeek86) May 18, 2015
While the ISE has been our friend for the past 6 years or so, it suffers from its own set of problems. It doesn’t provide as robust a framework for extensions as Visual Studio, and it doesn’t have the same level of flexibility for configuring keyboard shortcuts. As a PowerShell script author, you should certainly be accustomed to the productivity benefits that keyboard shortcuts provide! Intellisense performance problems also plague the ISE, as you’ll frequently see Intellisense timeouts occur, with few options to work around them, or better yet, fix them for good.
Because the ISE doesn’t support the notion of project files, it can be very challenging to keep track of which files make up your project, and keep track of which files are currently open. It simply doesn’t do as good of a job at window management as Visual Studio does.
When it comes to essential text editing functions, like search & replace, Visual Studio’s mechanism is significantly more robust, allowing you to search through your entire project, or all open files, at once.
If you’re using old or basic tools, like Notepad, Sublime Text, or Quest (now Dell) PowerGUI, I would strongly encourage you to check out the Visual Studio PoshTools Extension and the PowerShell Integrated Scripting Editor (ISE)!! You’ll benefit from syntax highlighting, auto-completion, code formatting, Intellisense, extensions, and much more!