执行bat文件到远程客户端

时间:2018-08-09 11:41:59

标签: powershell batch-file invoke-command

我试图通过执行以下波纹管shellshell命令

向客户端“ ClientA”打开一个HTML文件,该客户端在本地远程复制到文件夹“ C:\ 1.html”
$Username = 'username'
$Password = 'password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList                 
$Username,$pass


Invoke-Command -ComputerName ClientA -ScriptBlock { Invoke-Expression - 
Command:"cmd.exe /c 'C:\1.bat'" } -credential $Cred

“ 1.bat”批次具有波纹管

START iexplore -k "C:\1.html"

执行没有错误...但是文件没有打开到远程客户端! 有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

该脚本是正确的,内部没有错误,但是可能没有按照您认为的那样做。

当调用远程管理会话时,PowerShell正在具有自己的会话的远程计算机上运行,​​该会话没有桌面交互,因此您不会从最终用户可能会保持登录状态的会话中在主Shell中启动Internet Explorer。

要再次检查您的代码是否正常工作,可以在1.bat中使用以下内容

START iexplore -k "C:\1.html"
echo %PATH% >> c:\patlog.txt
echo "DONE" >> c:\1_log.txt

您将在控制台上看到路径和最后一个“完成”的回声,确认蝙蝠已被执行。

无论如何,Internet Explorer都不会在任何登录的用户会话中显示,这也将在本页上进行讨论:

https://serverfault.com/questions/690852/use-powershell-to-start-a-gui-program-on-a-remote-machine