提供三种方法
1、直接使用 Get-Host
PS C:\Program Files\clznode\bin> Get-Host
Name : ConsoleHost
Version : 4.0
InstanceId : d9787d3f-44d6-40ad-8fcf-90ca3ef945ae
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : ja-JP
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
2、使用$host变量
PS C:\Program Files\clznode\bin> $host.version
Major Minor Build Revision
----- ----- ----- --------
4 0 -1 -1
3、检查 $PSVersionTable 变量,PS2里有 $PSVersionTable变量,而PS1里没有
PS C:\Users\TopSage> if (test-path variable:psversiontable) {$psversiontable.psversion} else {[version]"1.0.0.0"}
Major Minor Build Revision
—– —– —– ——–
4 0 -1 -1