PowerShell can run on various platforms these days, and in the previous tip we explained how you find out the operating system that your scripts are running on.

If the operating system is Windows, you still don’t know whether your script is run by the built-in Windows PowerShell or by the new portable PowerShell 7.

Here is a safe and backward-compatible way to find out whether your script currently runs on Windows PowerShell or not:

$RunOnWPS = !($PSVersionTable.ContainsKey('PSEdition') -and 
              $PSVersionTable.PSEdition -eq 'Core')

"Runs on Windows PowerShell? $RunOnWPS"

Twitter This Tip! ReTweet this Tip!