Using Experimental Features in PowerShell
The Experimental Features support in PowerShell provides a mechanism for experimental features to coexist with existing stable features in PowerShell or PowerShell modules.
An experimental feature is one where the design isn't finalized. The feature is available for users to test and provide feedback. Once an experimental feature is finalized, the design changes become breaking changes.
Caution
Experimental features aren't intended to be used in production since the changes are allowed to be breaking. Experimental features aren't officially supported. However, we appreciate any feedback and bug reports. You can file issues in the GitHub source repository.
For more information about enabling or disabling these features, see about_Experimental_Features.
Available features
This article describes the experimental features that are available and how to use the feature.
Legend
- The
icon indicates that the experimental feature is available in the version of PowerShell
- The
icon indicates the version of PowerShell where the experimental feature became mainstream
- The
icon indicates the version of PowerShell where the experimental feature was removed
| Name | 7.2 | 7.3 | 7.4 |
|---|---|---|---|
| PSCommandNotFoundSuggestion | |||
| PSDesiredStateConfiguration.InvokeDscResource (DSC v2) | |||
| PSNativePSPathResolution | |||
| PSSubsystemPluginModel | |||
| PSNativeCommandArgumentPassing | |||
| PSAnsiRenderingFileInfo | |||
| PSLoadAssemblyFromNativeCode | |||
| PSNativeCommandErrorActionPreference | |||
| PSCustomTableHeaderLabelDecoration | |||
| PSFeedbackProvider | |||
| PSModuleAutoLoadSkipOfflineFiles |
PSAMSIMethodInvocationLogging
Note
This experiment was added in PowerShell 7.3.
For more information about AMSI, see How AMSI helps.
PSAnsiRenderingFileInfo
Note
This feature became mainstream in PowerShell 7.3.
This experiment was added in PowerShell 7.2. This feature adds the $PSStyle.FileInfo member and enables coloring of specific file types.
$PSStyle.FileInfo.Directory- Built-in member to specify color for directories$PSStyle.FileInfo.SymbolicLink- Built-in member to specify color for symbolic links$PSStyle.FileInfo.Executable- Built-in member to specify color for executables.$PSStyle.FileInfo.Extension- Use this member to define colors for different file extensions. The Extension member pre-includes extensions for archive and PowerShell files.
For more information, see about_Automatic_Variables.
Note
This feature is dependent on the PSAnsiRendering feature that's now a standard feature.
PSCommandNotFoundSuggestion
Recommends potential commands based on fuzzy matching search after a CommandNotFoundException.
PS> get
get: The term 'get' isn't recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
Suggestion [4,General]: The most similar commands are: set, del, ft, gal, gbp, gc, gci,
gcm, gdr, gcs.
PSCustomTableHeaderLabelDecoration
When this feature is enabled, $PSStyle includes formatting differentiation for table header labels
that aren't property members. For example, the default output from Get-Process includes the
following columns: NPM(K), PM(M), WS(M), and CPU(s).
Get-Process pwsh
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
99 84.57 170.50 5.89 48688 1 pwsh
73 87.75 133.08 3.09 49120 1 pwsh
98 70.31 158.56 4.23 91220 1 pwsh
125 70.19 171.33 4.84 92124 1 pwsh
These column names don't match any properties of the System.Diagnostics.Process object returned by the cmdlet. These are values calculated by the PowerShell formatting system.
With this feature enabled these column headers are displayed in italics to distinguish these column names from property names.
PSDesiredStateConfiguration.InvokeDscResource
Enables compilation to MOF on non-Windows systems and enables the use of Invoke-DSCResource
without an LCM.
In earlier previews of PowerShell 7.2, this feature was enabled by default. Beginning with
PowerShell 7.2, the PSDesiredStateConfiguration module was removed and this feature is disabled
by default. To enable this feature you must install the PSDesiredStateConfiguration v2.0.5
module from the PowerShell Gallery and enable the feature using Enable-ExperimentalFeature.
DSC v3 doesn't have this experimental feature. DSC v3 only supports Invoke-DSCResource and doesn't
use or support MOF compilation. For more information, see
PowerShell Desired State Configuration v3.
PSFeedbackProvider
Replace the hard-coded suggestion framework with the extensible feedback provider.
PSLoadAssemblyFromNativeCode
Exposes an API to allow assembly loading from native code.
PSModuleAutoLoadSkipOfflineFiles
With this feature enabled, if a user's PSModulePath contains a folder from a cloud provider, such as OneDrive, PowerShell no longer triggers the download of all files contained within that folder. Any file marked as not downloaded are skipped. Users who use cloud providers to sync their modules between machines should mark the module folder as Pinned or the equivalent status for providers other than OneDrive. Marking the module folder as Pinned ensures that the files are always kept on disk.
PSNativeCommandArgumentPassing
Note
This feature became mainstream in PowerShell 7.3.
When this experimental feature is enabled PowerShell uses the ArgumentList property of the
StartProcessInfo object rather than our current mechanism of reconstructing a string when invoking
a native executable.
Caution
The new behavior is a breaking change from current behavior. This may break scripts and automation that work around the various issues when invoking native applications. Historically, quotes must be escaped and it isn't possible to provide empty arguments to a native application.
Use the stop-parsing token (--%) or the Start-Process cmdlet to sidestep native
argument passing when needed.
This feature adds a new automatic variable $PSNativeCommandArgumentPassing that allows you to
select the behavior at runtime. The valid values are Legacy, Standard, and Windows. Legacy
is the historic behavior. The default when the experimental feature is enabled is the new Standard
behavior.
When the preference variable is set to Windows, invocations of the following files automatically
use the Legacy style argument passing.
cmd.exefind.execscript.exewscript.exesqlcmd.exe- Added in PowerShell 7.3.1- ending with
.bat - ending with
.cmd - ending with
.js - ending with
.vbs - ending with
.wsf
If the $PSNativeCommandArgumentPassing is set to either Legacy or Standard, the check for
these files doesn't occur. The default behavior is platform specific. On Windows platforms, the
default setting is Windows and non-Windows platforms is Standard.
New behaviors made available by this change:
Literal or expandable strings with embedded quotes the quotes are now preserved:
PS > $a = 'a" "b' PS > $PSNativeCommandArgumentPassing = "Legacy" PS > testexe -echoargs $a 'a" "b' a" "b Arg 0 is <a b> Arg 1 is <a b> Arg 2 is <a b> PS > $PSNativeCommandArgumentPassing = "Standard" PS > testexe -echoargs $a 'a" "b' a" "b Arg 0 is <a" "b> Arg 1 is <a" "b> Arg 2 is <a b>Empty strings as arguments are now preserved:
PS> $PSNativeCommandArgumentPassing = "Legacy" PS> testexe -echoargs '' a b '' Arg 0 is <a> Arg 1 is <b> PS> $PSNativeCommandArgumentPassing = "Standard" PS> testexe -echoargs '' a b '' Arg 0 is <> Arg 1 is <a> Arg 2 is <b> Arg 3 is <>
The new behavior doesn't change invocations that look like this:
PS> $PSNativeCommandArgumentPassing = "Legacy"
PS> testexe -echoargs -k com:port=\\devbox\pipe\debug,pipe,resets=0,reconnect
Arg 0 is <-k>
Arg 1 is <com:port=\\devbox\pipe\debug,pipe,resets=0,reconnect>
PS> $PSNativeCommandArgumentPassing = "Standard"
PS> testexe -echoargs -k com:port=\\devbox\pipe\debug,pipe,resets=0,reconnect
Arg 0 is <-k>
Arg 1 is <com:port=\\devbox\pipe\debug,pipe,resets=0,reconnect>
Additionally, parameter tracing is now provided so Trace-Command provides useful information
for debugging.
PS> $PSNativeCommandArgumentPassing = "Legacy"
PS> trace-command -PSHOST -Name ParameterBinding { testexe -echoargs $a 'a" "b' a" "b }
DEBUG: 2021-02-01 17:19:53.6438 ParameterBinding Information: 0 : BIND NAMED native application line args [/Users/james/src/github/forks/jameswtruher/PowerShell-1/test/tools/TestExe/bin/testexe]
DEBUG: 2021-02-01 17:19:53.6440 ParameterBinding Information: 0 : BIND argument [-echoargs a" "b a" "b "a b"]
DEBUG: 2021-02-01 17:19:53.6522 ParameterBinding Information: 0 : CALLING BeginProcessing
Arg 0 is <a b>
Arg 1 is <a b>
Arg 2 is <a b>
PS> $PSNativeCommandArgumentPassing = "Standard"
PS> trace-command -PSHOST -Name ParameterBinding { testexe -echoargs $a 'a" "b' a" "b }
DEBUG: 2021-02-01 17:20:01.9829 ParameterBinding Information: 0 : BIND NAMED native application line args [/Users/james/src/github/forks/jameswtruher/PowerShell-1/test/tools/TestExe/bin/testexe]
DEBUG: 2021-02-01 17:20:01.9829 ParameterBinding Information: 0 : BIND cmd line arg [-echoargs] to position [0]
DEBUG: 2021-02-01 17:20:01.9830 ParameterBinding Information: 0 : BIND cmd line arg [a" "b] to position [1]
DEBUG: 2021-02-01 17:20:01.9830 ParameterBinding Information: 0 : BIND cmd line arg [a" "b] to position [2]
DEBUG: 2021-02-01 17:20:01.9831 ParameterBinding Information: 0 : BIND cmd line arg [a b] to position [3]
DEBUG: 2021-02-01 17:20:01.9908 ParameterBinding Information: 0 : CALLING BeginProcessing
Arg 0 is <a" "b>
Arg 1 is <a" "b>
Arg 2 is <a b>
PSNativeCommandErrorActionPreference
Native commands usually return an exit code to the calling application that's zero for success or non-zero for failure. However, native commands currently don't participate in the PowerShell error stream. Redirected stderr output isn't interpreted the same as the PowerShell error stream. Many native commands use stderr as an information or verbose stream, thus only the exit code matters. Users working with native commands in their scripts need to check the exit status after each call using similar to the following example:
if ($LASTEXITCODE -ne 0) {
throw "Command failed. See above errors for details"
}
However, this example doesn't support all cases where $? can be false from a cmdlet or function
error, making $LASTEXITCODE stale.
This feature implements the $PSNativeCommandUseErrorActionPreference preference variable that
controls how native commands errors are handled in PowerShell. This allows native command failures
to produce error objects that are added to the PowerShell error stream and may terminate execution
of the script without extra handling.
To enable this feature, run the following commands:
Enable-ExperimentalFeature PSNativeCommandErrorActionPreference
You must start a new PowerShell session for this change to be in effect. Beginning in PowerShell
7.4, $PSNativeCommandUseErrorActionPreference is set to $true by default. With the preference
set to $true you get the following behavior:
- When
$ErrorActionPreference = 'Stop', scripts will break when a native command returns a non-zero exit code. - When
$ErrorActionPreference = 'Continue'(the default), you will see PowerShell error messages for native command errors, but scripts won't break.
PSNativePSPathResolution
Note
This experimental feature was removed in PowerShell 7.3 and is no longer supported.
If a PSDrive path that uses the FileSystem provider is passed to a native command, the resolved file
path is passed to the native command. This means a command like code temp:/test.txt now works as
expected.
Also, on Windows, if the path starts with ~, that's resolved to the full path and passed to the
native command. In both cases, the path is normalized to the directory separators for the relevant
operating system.
- If the path isn't a PSDrive or
~(on Windows), then path normalization doesn't occur - If the path is in single quotes, then it's not resolved and treated as literal
PSSubsystemPluginModel
This feature enables the subsystem plugin model in PowerShell. The feature makes it possible to
separate components of System.Management.Automation.dll into individual subsystems that reside in
their own assembly. This separation reduces the disk footprint of the core PowerShell engine and
allows these components to become optional features for a minimal PowerShell installation.
Currently, only the CommandPredictor subsystem is supported. This subsystem is used along with
the PSReadLine module to provide custom prediction plugins. In future, Job,
CommandCompleter, Remoting and other components could be separated into subsystem assemblies
outside of System.Management.Automation.dll.
The experimental feature includes a new cmdlet, Get-PSSubsystem. This cmdlet is only available when the feature is enabled. This cmdlet returns information about the subsystems that are available on the system.
Feedback
Submit and view feedback for