【发布时间】:2013-12-03 12:23:56
【问题描述】:
我正在尝试通过如下驱动器映射在远程服务器上运行批处理文件,但进程挂起...
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”我驾驶的车并查看预期的内容。
当我执行以下操作时,进程挂起 -
Invoke-Command -Session $RemoteSession -ScriptBlock { Start-Process I:\temp.bat }
temp.bat 文件执行以下命令,我已手动验证它是否有效
echo Scott was here > C:\temp.txt
但是,该命令运行超过 5 分钟而没有任何响应。
有人可以帮忙吗?我做错了什么?
【问题讨论】:
-
由于 Start-Process 不等待进程完成,我不明白为什么会这样。您是否尝试过用 powershell 命令替换批处理文件?
-
嗨,Lars,我没有,没有。我需要运行的实际文件是第三方批处理文件,所以我不确定有什么意义。我最初认为是这个文件有问题,这就是为什么我将调用更改为重定向的 echo 语句(如上)。
-
Lars,你过去有没有看到任何可以解释这一点的东西?非常感谢您的帮助...
-
可能与您的重定向有关。您可以尝试删除批处理中的
> C:\temp.txt,并将-RedirectStandardOutput C:\temp.txt作为参数附加到Start-Process吗? -
嗨,安东尼,我下周试试。唯一的问题是没有重定向,我不知道它是否有效!还有其他证明方法吗?谢谢
标签: powershell