The latest version 188.8.131.52 of ISESteroids comes with CompatAware, a brand new technology to help you safely develop against different PowerShell versions.
What is CompatAware?
CompatAware is a technology that can determine which part of your code is incompatible to a given PowerShell version.
CompatAware will mark incompatible code in real-time with yellow squiggles, and when you hover over the squiggle, you immediately see in a tooltip what the requirements are.
To start the check, open the “Level” menu and go to CompatAware, then pick the PowerShell target version. Immediately, all code that is incompatible to this version gets marked.
CompatAware will also mark incompatible structures, such as workflows, configurations, or classes.
In addition, you can check “Mark non-default commands”. When checked, CompatAware will also mark cmdlets and applications that are not part of any PowerShell version, and the tooltip tells you the name of the module that is required for this command.
Based on the CompatAware information, you can automatically update or create a #requires statement for your script. Simply choose “Add/update #requires statement”, or press CTRL+ALT+R. CompatAware adds the correct #requires statement to your script.
A #requires statement is a great way of documenting what the requirements for your script are, and PowerShell takes that information and prevents the script from running in an incompatible environment.
Creating Compatibility Reports
But wait, there is more: when you choose “Compatibility Report”, CompatAware creates an extensive compatibility report, including all the commands and structures that are incompatible with a given target version, and optionally including any script dependencies to external modules.
The command really just runs Get-SteroidsCompatibilityReport and pipes the results to Out-GridView. You can just as easily take the data and use it in your own reporting. Note that each line of this report has a “Data” property. It contains the actual Ast element, so you can use it to pinpoint the offending command or structure.
There is tons of additional stuff in this release. I’d just like to highlight three things:
- ISESteroids now marks runtime errors in your script. So when you run a script, and the script produces errors, red squiggle lines will show you exactly where in your script this happened, and when you hover over the squiggles, a tooltip explains the error. The same tooltip now works for any squiggle.
To clarify: previously, only static syntax errors would receive a red squiggle line. Now, dynamic runtime errors will be treated like this, too. This works both in saved and in Untitled scripts.
- Syntax errors can now have personal annotations. Your personal annotations show in the syntax error tooltip when you hover over a red squiggle line. To add your notes, right-click the warning sign in the debugger margin, and add your note. Personal notes are a great way of attaching your wisdom to errors.
- And a minor but effective addition: To insert a real TAB in your editor, simply hold CTRL while pressing TAB. This will temporarily disable Intellisense, and the TAB gets inserted.