PowerShell installation folder and script file name extension by version

Wikipedia says that PowerShell 2.0 was distributed with Windows 7; since I am using Windows 7, I am obviously using this version.

But this raises two questions:

  • Why is the PowerShell folder C:\Windows\System32\WindowsPowerShell\v1.0 with this trailing v1.0 when it really should be v2.0 ?
  • Why is the PowerShell script .ps1 extension? Will there be an increase in this extension when changing the version?
+4
source share
2 answers

This is simply the result of a selection made by the Powershell team. They decided to keep both the 1.0 directory and the .ps1 extension for V2 powershell.

The best way to check the Powershell version is to use the expression $PSVersionTable.PSVersion

 C:\Users\jaredpar> $PSVersionTable.PSVersion Major Minor Build Revision ----- ----- ----- -------- 2 0 -1 -1 
+2
source

This is an ancient blog post (2007), but it still applies; Shortly speaking:

  • As long as new versions of PowerShell remain backward compatible, they replace earlier versions :

    • The installation location displayed in $PSHOME - $env:systemroot\System32\WindowsPowerShell\v1.0 , will remain the same.

    • The file name extension - .ps1 - will remain the same.

  • Scripts created for an earlier version will continue to work.

  • To mark the script as the required version of <n> at least, use #requires -version <n> at the top of the script (technically it can be placed anywhere in the script, but it makes sense to put it on top).

At the time of this writing (PowerShell v5.1) with v1, backward compatibility was supported, so the installation location and file name extension remained the same.


To get the current session of a PowerShell version :

 > [string] $PSVersionTable.PSVersion 5.1.14393.693 # PSv5.1 example 

In general, the hashtable $PSVersionTable introduced in v2 contains several parts of the version information (not fully) described in Get-Help about_Automatic_Variables :

 Name Value ---- ----- PSVersion 5.1.14393.693 # The PowerShell version. PSEdition Desktop # 'Desktop'=*Windows* PS; 'Core'=PS *Core* PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} # array of compatible versions BuildVersion 10.0.14393.693 # OS version? only if it came natively CLRVersion 4.0.30319.42000 # The .NET CLR version WSManStackVersion 3.0 # WS-Management (WinRM) version PSRemotingProtocolVersion 2.3 # remoting-protocol version SerializationVersion 1.1.0.1 # serialization-protocol version 
+1
source

All Articles