CompatAware

CompatAware enables you to safely script against different PowerShell versions. CompatAware highlights incompatible commands, parameters, and language constructs.

CompatAware also highlights external module dependencies that are required by a script, and can automatically add or update a #requires statement, making sure a script runs only if all of its requirements are met.

Targeting a PowerShell Version

To target a PowerShell version, open the menu “Level”, then choose “CompatAware”, and pick the PowerShell version you want to target.

Enabling CompatAware

The moment you set a PowerShell target version, ISESteroids starts to highlight all cmdlets, parameters, and language constructs that are not compatible with this version. A yellow squiggle line indicates incompatibilities in real-time, while you code.

Hover over a yellow squiggle line to learn more about the detected incompatibility.

Detect Incompatibility

Finding Dependencies

CompatAware is not limited to PowerShell compatibility issues. It can also pinpoint vital code dependencies, like required external modules or commands.

To get dependency information, open the “Level” menu, choose “CompatAware”, then enable “Mark non-default commands”. Once you do this, ISESteroids adds a yellow squiggle to all commands that are not shipping with PowerShell. This helps you quickly identify commands that originate in optional 3rd party modules.

Finding Dependencies

Auto-Generating #requires Statements

To play safe, a script should either run successfully, or not run at all. The worst scenario is a script that stalls in the middle of something, leaving you with a lot of cleanup work.

PowerShell scripts can add a #requires statement, listing all the requirements your script needs to successfully run. Since CompatAware already knows what your script needs, it can derive and auto-generate the correct #requires statement for your script. Existing #requires statements are properly updated.

Simply visit the CompatAware menu, and choose “Add/Update #requires statement”, or press CTRL+ALT+R.

You can also use the cmdlet Update-SteroidsRequiresStatement, or run the refactoring addon (the button shows a green checkmark). It will add or update #requires statements automatically as part of the code optimization rules tied to it.

Adding #requires

Generating Compatibility Reports

CompatAware shares the compatibility info it gathers. So you can create compatibility reports, or use the compatibility information in your own reporting tools.

To get a compatibility report, visit again the CompatAware menu, and choose “Compatibility Report”. The rich object data can also be directly retrieved:

Get-SteroidsCompatibilityReport -TargetVersion 2 -IncludeDependencies

(Replace “2” with the PowerShell version you want to check against).

 

Facebooktwittergoogle_pluspinterestlinkedinFacebooktwittergoogle_pluspinterestlinkedin