Hidden Charms of PowerShell Studio
- Written by June Blender
- Last Updated: 03 October 2016
- Created: 28 September 2015
- Hits: 3162
I’m coming up on my one-year anniversary at SAPIEN Technologies, Inc. and my one-year anniversary of using PowerShell Studio as my primary IDE. When I speak at conferences and user groups, I don’t typically talk about products, because people don’t want to hear “vendor talks.” But, in private, I’ve become a total PowerShell Studio fan-girl. It’s a bit embarrassing, honestly.
I love the big powerhouse features, like PowerShell GUI automation, .EXE and .MSI creation, the Function Builder and Parameter Builder, and New Module from Functions. But, it’s the smaller, quieter features that have me hooked. Here’s my list of can’t-live-without-’em features of PowerShell Studio. Do you have a different list? Share in the comments below.
And, don't miss the second installment of this article: Hidden Charms of PowerShell Studio #2.
10. Expand all aliases
I’m a huge proponent of Windows PowerShell best practices, but like everyone else, my instinctive behaviors don’t always meet my coding standards. Before I share any script or function, or even a code sample, I press Ctrl + Shift + A, to replace all cmdlet, function, and parameter aliases with their correct full names.
The Qualify Cmdlet Names feature (Ctrl+Shift+H) is a great addition, too, especially with the proliferation of cmdlets and modules in open source.
9. Generate comment-based help
It’s predictable that I would love this feature. What’s less predictable is how often I use it. Like all the time.
I jump in, write my function, add parameters, and then right-click and click Generate comment-based help. It parses my code and adds starter help, including help for my parameters. Comment-based help is error-prone; one typo in a keyword causes Get-Help to ignore the whole comment block, so I really rely on my tools, including this feature, to avoid errors.
8. Snippets with variables and help
Lots of tools have snippets, but I’ve never seen one with better support for variables and help in snippets. I use the tooltip/help feature in PowerShell Studio snippets to remind me to do things that I might otherwise forget, like adding quotation marks to PSCustomObject hash table values.
7. Parameter set history
PowerShell Studio maintains a history of the parameter sets that you run. And, it maintains a separate history for the Run and Debug command series.
Good code-coverage testing depends on testing parameter combinations. Before I had the parameter history, I used all sorts of tricks to remember the parameters that I tested, including filling pages of OneNote with notes that were tough to decipher. Now, PowerShell Studio just does it automatically.
6. Spotlight articles
TechNet is useful. So is MSDN. But, there’s nothing like a reference that is specific to the current task. When I’m building a PowerShell GUI app, the SAPIEN Spotlight articles are my go-to reference. They describe the control, its default event, and most commonly used properties.
They’re brief, clear, designed for GUI beginners, and the examples are all PowerShell, not C# or VB. I like the Spotlight articles so much that when I have an extra minute, I click a random control and read its spotlight article to give me ideas for my next PowerShell GUI app.
By the way, the Spotlight articles are the work of SAPIEN Senior Developer David Corrales. If you like them, next time you see David, be sure to thank him.
5. Restart shell
The Restart shell feature of the Console pane kills the PowerShell process that’s running in the Console pane and starts a new process. This lets me test and retest (and retest) my features without disturbing the code in my Editor pane or interrupting my work.
When I demonstrate features, I restart the console often, sometimes to emphasize that elements of the code are independent, but most often to keep items saved in the session, like variables, functions, and classes, from affecting the result of the next command.
4. Run and Run in console
The Run in Console feature doesn’t just run a script in the Console pane — it dot-sources it. Dot-sourcing adds the items in the script scope, including function, script-scoped variables, classes, and workflows, to the console, so they’re available even after the script completes.
This feature is fantastic for testing and demonstrations, because after running the script, it lets you use and test the script elements in different ways and examine the effect of the persistent elements on the environment.
Run is really different. It’s the epitome of best-practice testing. Run creates a new session that never includes local artifacts, like your Windows PowerShell profile, or session-specific items, like variables, and then runs the script in the clean-slate session.
I use both Run and Run in Console continuously. I can’t imagine a scripting environment that didn’t have both tools.
3. Copy HTML
If you blog, the Copy HTML feature is your friend. For me, it’s a best friend. I used to fiddle with <pre> tags and plugins. Now, when I want to include code in a blog post, I right click the code in PowerShell Studio, click Copy HTML, and then paste the HTML for the code in the Text view of the post. The result is perfectly copied code, including color coding and formatting.
2. File groups
For presentations and demos, for testing and spec reviews, you often have multiple files to display. And, you don’t want to start finding and loading the files at the last minute.
PowerShell Studio lets you create a filegroup, which is, essentially, a list of files in a specified order that you open in a single click. The files don’t need to be in the same location, or on the same computer.
When you’re ready to present, you just click the file group. PowerShell Studio opens the files and displays them in the specified order. Whew!
And, adding files to a file group doesn’t change the constituent files or their filenames, so it doesn’t affect the presentation at all. Stellar feature.
1. Format Script button
The one PowerShell Studio feature that I can’t live without is not the Update-Help button, which I love, or the Watch window in the debugger, which keeps me sane. Instead, it’s the Format Script button.
Good formatting isn’t just a visual aid. It also helps me to recognize, avoid, and eliminate errors. When I’m coding, especially refactoring, and my script indentation or line breaks become inconsistent, I don’t have to start tabbing or spacing, or looking for enclosure matches. I just click Format Script.
PowerShell Studio makes me efficient and productive. I rely on the major features all the time, but it’s the tiny hidden charms that make my life easier and make me a better and more professional coder.
See the 2016 update: Hidden Charms of PowerShell Studio #2.