PowerShell 中的 If / Else 结构存在问题。我们的脚本适用于以前的 Windows 版本(直至 Windows Server 2012 R2),但不适用于较新的版本。
为了简单起见,我们以 PowerShell 帮助 ( Get-Help about_If) 中的一个示例为例:
if ($a -gt 2)
{
Write-Host "The value $a is greater than 2."
}
else
{
Write-Host "The value $a is less than or equal to 2, is not created or is not initialized."
}
Run Code Online (Sandbox Code Playgroud)
在 Windows Server 2012 R2(基于的 PowerShell 版本是 5.1.14409.1018)上$PSVersionTable.PSVersion,结果如下:
The value is less than or equal to 2, is not created or is not …Run Code Online (Sandbox Code Playgroud) powershell ×1