提供三种方法
1. 直接使用 Get-Host
PS C:\Users\TopSage> Get-Host
Name : ConsoleHost
Version : 2.0
InstanceId : b354f4bf-ff4e-452a-b747-78267a914c0a
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : zh-CN
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
2. 使用$host变量
PS C:\Users\TopSage> $host.version
Major Minor Build Revision
—– —– —– ——–
2 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
—– —– —– ——–
2 0 -1 -1