我们正在为仅在Powershell 2.0中工作的客户提供脚本。
通过命令,我们可以确保如下安装powershell 2.0
$version = Get-host | Select-object Version
但是,如果我们提供脚本如何确保他们从Powershell 2.0执行它?
执行脚本时,Powershell 2.0功能可能会在启动脚本时发出脚本错误。不是吗?
答案 0 :(得分:2)
我会做这样的事情:
# get version
$ver = $PsVersionTable.psversion.major
# Check to see if it's V2
If ($ver -NE 2)
{"incorrect version - exiting; return}
# Everything that follows is V2
希望这有帮助!
答案 1 :(得分:0)
尝试使用$PSVersionTable
你会得到类似的东西:
Name Value
---- -----
CLRVersion 2.0.50727.5456
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1