小编pho*_*par的帖子

术语“else”未被识别为 cmdlet 的名称

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

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

powershell ×1