powershell/PSUseCompatibleCommands is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
Description
This rule identifies commands that are not available on a targeted PowerShell platform.This page describes upstream PSScriptAnalyzer compatibility profiles. tally runs the analyzer through PowerShell 7 (
pwsh); Windows PowerShell 5.1
(powershell.exe) is out of scope as a sidecar host.<os-name>: The name of the operating system PowerShell is running on. On Windows, this includes the SKU number. On Linux, this is the name of the distribution.<os-arch>: The machine architecture the operating system is running on (this is usuallyx64).<os-version>: The self-reported version of the operating system (on Linux, this is the distribution version).<ps-version>: The PowerShell version (from$PSVersionTable.PSVersion).<ps-arch>: The machine architecture of the PowerShell process.<dotnet-version>: The reported version of the .NET runtime PowerShell is running on (fromSystem.Environment.Version).<dotnet-edition>: The .NET runtime flavor PowerShell is running on (currentlyframeworkorcore).
win-4_x64_10.0.18312.0_5.1.18312.1000_x64_4.0.30319.42000_frameworkis PowerShell 5.1 running on Windows 10 Enterprise (build 18312) for x64.win-4_x64_10.0.18312.0_6.1.2_x64_4.0.30319.42000_coreis PowerShell 6.1.2 running on the same operating system.ubuntu_x64_18.04_6.2.0_x64_4.0.30319.42000_coreis PowerShell 6.2.0 running on Ubuntu 18.04.
Other profiles can be found in the GitHub repo.
You can also generate your own platform profile using the PSCompatibilityCollector module.
The compatibility profile settings takes a list of platforms to target under
TargetProfiles. A
platform can be specified as:
- A platform name (like
ubuntu_x64_18.04_6.1.1_x64_4.0.30319.42000_core), which will have.jsonadded to the end and is searched for in the default profile directory. - A filename (like
my_custom_platform.json), which will be searched for in the default profile directory. - An absolute path to a file (like
D:\PowerShellProfiles\TargetMachine.json).
$PSScriptRoot/compatibility_profiles (where $PSScriptRoot here refers to the directory
containing PSScriptAnalyzer.psd1).
The compatibility analysis compares a command used to both a target profile and a ‘union’ profile
(containing all commands available in any profile in the profile dir). If a command is not present
in the union profile, it is assumed to be locally created and ignored. Otherwise, if a command is
present in the union profile but not present in a target, it is deemed to be incompatible with that
target.
Configuration settings
An example configuration might look like:
Suppression
Command compatibility diagnostics can be suppressed with an attribute on theparam block of a
scriptblock as with other rules.