I am using PowerShell
and PowerShell Core
in parallel.
Not all my scripts which I have wrote for the "big" PowerShell are working in PowerShell Core and vice versa.
To avoid chaos, I was thinking if I should use two file-extensions:
.ps1
: PowerShell.pwsh
: PowerShell CoreIn Windows the extension is more important then in Unix systems where the shebang
(#!/bin/mytool) would help to solve the problem.
Is the usage of two extension "best practice" or there are better options?
Additional: I am not sure if a .pwsh
script will be executed by PowerShell when I call a script from command line / terminal.
I found a similar question in Unix / Linux context. https://unix.stackexchange.com/questions/182882/use-sh-or-bash-extension-for-bash-scripts
Add a line
#requires -PSEdition Core
at the beginning of your scripts for PowerShell Core, and a line
#requires -PSEdition Desktop
at the beginning of your scripts for regular PowerShell.
For scripts that run in both editions just omit the line.
From the documentation:
-PSEdition <PSEdition-Name>
Specifies a PowerShell edition that the script requires. Valid values are Core for PowerShell Core and Desktop for Windows PowerShell.
Do not use different extensions, as that will impact functionality. For instance, PowerShell will not dot-source scripts with an extension other than .ps1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With