Powershell #Requires path/to/Name.exe

Powershell #Requires path/to/Name.exe

如果 'foobar.exe' 不在正确的位置,我想阻止我的脚本 运行。 IE。 'C:\path\to\Foobar.exe'

我试过 #Requires -Assembly 'path\to\Foobar.exe' 但它抛出错误 该错误不清楚如何解决。

如果我不能使用 #Requires 如果它的 'Foobar.exe' 不在 path\to.[=15 中,是否有不同的方法来阻止脚本 运行 =]

就把它放在脚本的开头吗?

If (-not (Test-Path -Path 'C:\Path\To\foo.exe')) {
    Throw "Cannot find 'C:\Path\To\foo.exe'"
}