我有以下 PowerShell 代码来测试脚本块中是否存在文件:
$scriptblock =
{
Param($filename)
return "Scriptblock filename $filename Exists? -> $(Test-Path $filename)"
}
$myFilename = "MyFile.xml"
Write-Host "Main filename $myFilename Exists? -> $(Test-Path $myFilename)"
$job = Start-Job -Name "myJob" -ScriptBlock $scriptBlock -ArgumentList $myFilename
$result = Receive-Job -Name "myJob"
Write-Host $result
当我运行它时,我得到以下输出,表明该文件存在于主执行中,但不存在于脚本块中。
Main filename MyFile.xml Exists? -> True
Scriptblock filename MyFile.xml Exists? -> False
有人可以指出在脚本块中测试文件是否存在需要什么吗?
谢谢!