我在PowerShell中编写了以下函数,由于某种原因,当我尝试打印变量以将其屏幕打印为空时(它执行从变量开始的命令,所以我知道值已被传递)-为什么?
function Verify-Command-Dependency {
Param($cmd, $name, $error)
Try
{
$result = "$name dependency installed."
Write-Host "$name"
Invoke-Expression -Command "$cmd" -OutVariable out
Write-Color -Text "[ ", "OK", " ] ", $result -Color White, Green, White, White
}
Catch
{
Write-Output $error
Break
}
}