0
這裏是代碼等待工作不等待
try{
$SetupJob = invoke-command -ComputerName $j -Credential $credentials -ScriptBlock $sb -AsJob | Out-Null
}
catch [System.Exception]{
continue
}
$SetupJob|Wait-Job
$disable_command = "D:\PSTools\PsExec.exe $comp -u Administrator -p $str -accepteula powershell.exe c:\share\ps_disable.ps1"
$CmdOutput = Invoke-Expression $disable_command 2>&1
Remove-Item Z:\ps_*able.ps1
Remove-Item Z:\setup.exe
$SetupJob
執行setup.exe
上REMOTE_COMPUTER。執行後,它應該被刪除。但是,我得到以下
Remove-Item : Cannot remove item \\remote_computer\share\setup.exe: The process cannot access the file '\\remote_computer\share\setup.exe' because it is being used by another process.
如何解決?
這有效,但它輸出到Powershell ISE控制檯。如何抑制這一點? – Glowie 2014-09-29 19:20:21
@Glowie我認爲你想將Wait-Job的輸出傳遞給Out-Null,而不是Invoke-Command的輸出。 – 2014-09-29 19:26:43