Archive for the ‘Best practices’ Category


Use PSScriptAnalyzer in PowerShell Studio

Wednesday, May 11th, 2016 by June Blender
Applies to: Windows PowerShell 3.0 and later PSScriptAnalyzer 1.1.0 and later PowerShell Studio 5.2.118 and later PowerShell Studio has long supported best practices in Windows PowerShell, including running and debugging without profiles, avoiding cmdlet and parameter aliases (right-click\Expand to cmdlet, Expand all aliases: Ctrl+Shift+A), using consistent formatting to make maintenance and debugging easier, and using module-qualified command names (Ctrl+Shift+H). Beginning in PowerShell Studio 5.2.118, we've added deep support for PSScriptAnalyzer, the static analysis tool designed especially for Windows PowerShell. To use the Script Analyzer features in PowerShell Studio, you must be running in Windows PowerShell 3.0 and later and have…   More »

Distributing files with your packaged scripts

Tuesday, March 22nd, 2016 by Alex Riedel
We get this question every week: Why can I not include my data files, secondary scripts, modules, other executables etc. with the packaged executable and have it unpack them when I run it? If you have been a SAPIEN customer for a few years you may remember that we had this feature in the packager until the 2012 version. The predominant operating system at the time was Windows XP and this worked fine. With the advent of Windows Vista and Windows 7 we received this question more and more: “Why does my packaged script no longer work?. You need…   More »

Open a SAPIEN Forum from PowerShell

Monday, March 21st, 2016 by June Blender
UPDATE:  Added a -Search parameter that searches all SAPIEN forums for the term that you specify and then opens the page with the results. Thanks to Prasoon V. Karunan for the contribution. I love helping people learn Windows PowerShell and SAPIEN products. I answer questions on Facebook, Twitter, Reddit (love the /r/powershell subreddit), Google+, Slack, email, in the line at Starbucks, etc. But, I'm also a scripter, and I know the value of automation and efficiency. So, rather than answer one question for one person, I'd rather answer each question for many people. And, to get the best answer, I'd like…   More »

Which versions of PowerShell do you run?

Tuesday, March 8th, 2016 by June Blender
The PowerShell team released Windows PowerShell 5.0 on Windows 10 last year and just re-released Windows Management Framework (WMF) 5.0 for earlier versions of Windows. But, we know from years of experience that many people don't upgrade their versions quickly. It takes time to get to know and trust a new version. In a large enterprise, it takes time to do the parallel testing to certify that a new product is secure and compatible with the software that the organization uses. Take the survey: Which version of Windows PowerShell do you use? For those of us who are writing scripts and modules to share, this…   More »

There’s only one right place for curly braces

Thursday, March 3rd, 2016 by June Blender
If you ever want to start an argument with programmers or scripters, mention your preferred code or script formatting habit. A tweet about the PowerShell backtick continuation character or the placement of comment-based help for a function will elicit enough reaction to bring down a small server. But nothing gets people more riled up than the position of curly braces in a script block. On the same line or a separate line? From First, PowerShell MVP Aleksandar Nikolic will remind you (and rightly so!) that "curly braces" is redundant, because all braces are curly. That's how you distinguish braces…   More »

Update-Module 5.0 adds, not updates

Wednesday, February 17th, 2016 by June Blender
Applies to: -- Windows PowerShell 5.0.10586.63 -- PowerShellGet I'm a huge fan of sharing Windows PowerShell modules and making them easy to find (Find-Module), view (Save-Module), and install (Install-Module). So, I truly love the new PowerShellGet module. However, you really need to understand how it works before you use it. Otherwise, you might end up with commands and modules that don't work correctly (or at all) or don't do what you expect. Or, you might download modules with commands that shadow or hide commands that your scripts run. Update-Module is one of the really useful cmdlets in PowerShellGet, but if you don't know…   More »

Using Prefixes to Prevent Command Name Collision

Monday, February 15th, 2016 by June Blender
In January, I had the honor of presenting to the Mississippi PowerShell User Group (MSPSUG). I've known the organizers, Mike Robbins and Rohn Edwards for years, and truly respect them. The PSUG is online-only, which makes it a challenge for presenters, but they attract a very sophisticated audience, so my talks there are really conversations. This was a perfect venue for my "Avoiding Version Chaos" talk. (More at PowerShell Saturday in Tampa on March 19, 2016.) In one part of the talk, I demonstrated how to use noun prefixes to distinguish among commands with the same names. The demo flopped…   More »

Using Group-Object to Detect Command Name Conflicts

Wednesday, February 10th, 2016 by June Blender
The Group-Object cmdlet, one of the original provider cmdlets, is as old as Windows PowerShell. It was introduced in version 1.0 and hasn't changed at all since then. But, it is one of my favorites. (You can tell when I love a cmdlet by the number of examples. Group-Object has 9!) In fact, when you use it frequently, you begin to see groups as a path to many solutions. Group-Object groups objects by the values of a property that you choose. So, it's a quick way to find the property values that appear in a data set. Which domain controllers are used by users…   More »

Running PowerShell Scripts: Survey Results

Monday, February 8th, 2016 by June Blender
We're always evaluating the best, easiest, and most efficient ways to write, run, and publish Windows Powershell scripts and modules. But, our starting point is always how people work now. We were curious about how PowerShell scripters, including managers, ran scripts, and how their employees ran scripts written for them.   To gather this information, SAPIEN Technologies, Inc. created an online survey about the ways in which users run PowerShell scripts. We encouraged users to participate in a blog post and several posts on Facebook and Twitter. And, people really responded. We collected 88 responses between 12/16/2015 and 1/05/2016.  …   More »

How I learned to love DialogResult

Wednesday, December 23rd, 2015 by June Blender
This post discusses the DialogResult property of buttons, which often confuses beginning PowerShell GUI app designers. When I first started learning how to write PowerShell GUI applications, I thought of the DialogResult property of buttons as the "evil property." What else would I think? If the DialogResult property of a button is set to any value other than None, when you click the button, the GUI app closes immediately after running the commands in my event handler. In this little app, when you click OK, it pipes a Get-Service command to Out-GridView -- um, very briefly. [video width="1280" height="670" mp4=""][/video]…   More »