我想通过驱动器映射的方式在远程服务器上运行批处理文件,但进程卡住了...
Enable-WSManCredSSP -Role Client -DelegateComputer someserver -Force
$credential = Get-Credential -Credential domain\user (then I supply the password in the popup)
$RemoteSession = New-PSSession -ComputerName someserver -Credential $credential -Authentication Credssp
Invoke-Command -Session $RemoteSession -ScriptBlock { Enable-WSManCredSSP -Role Server -Force }
Invoke-Command -Session $RemoteSession -ScriptBlock { New-PSDrive -Name I -PSProvider FileSystem -Root \\server\share$ }
到目前为止,一切都看起来很正常,我可以通过“dir”命令查看I驱动器并看到期望的内容。
但是当我执行以下操作时,进程会挂起 -
Invoke-Command -Session $RemoteSession -ScriptBlock { Start-Process I:\temp.bat }
temp.bat文件执行以下命令,我已经手动验证过它可以工作
echo Scott was here > C:\temp.txt
然而,该命令运行超过5分钟而没有任何响应。
有人可以帮忙吗?我做错了什么?
> C:\temp.txt
,并将-RedirectStandardOutput C:\temp.txt
作为参数添加到Start-Process
中。 - Anthony Neace$lastexitcode
来实现此目的。您可以在以下线程中找到示例: https://dev59.com/QWoy5IYBdhLWcg3wcNrh - Paul