首页 > 解决方案 > 如何在会话之外与远程机器交互?

问题描述

我想在我的一些域计算机上静默安装软件。由于这些软件包不是以 MSI 的形式出现的,我想我会尝试使用 Powershell 来实现。

第一步,我设置了 Powershell 远程处理。以下命令有效:

PS $ Test-WSMan -ComputerName rmtComputer

wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 3.0

要安装的软件包位于网络共享上。不幸的是,似乎无法直接启动这些安装文件。正如 Kevin Marquette 在他关于 Powershell 的文章中解释的那样,这是由于一些双跳凭证问题造成的。解决方案是先将设置文件从共享复制到本地文件夹,然后开始设置。

在同一篇文章中,他展示了两种方法。第一种方式如下所示:

Copy-Item -Path $file -Destination "\\$computername\c$\windows\temp\installer.exe"
Invoke-Command -ComputerName $computerName -ScriptBlock {
    c:\windows\temp\installer.exe /silent
}

这两个命令都不适合我。运行copy-item命令返回The network path was not found。我可以确认计算机和用户都具有对各自共享的读取权限。

运行该invoke-command命令不会返回任何错误,但有问题的计算机上没有任何反应。

Marquette 继续描述了另一种使用远程会话的方法:

$session = New-PSSession -ComputerName $computerName
Copy-Item -Path $file -ToSession $session -Destination 'c:\windows\temp\installer.exe'

Invoke-Command -Session $session -ScriptBlock {
    c:\windows\temp\installer.exe /silent
}
Remove-PSSession $session

另一方面,这非常有效。你可以给我任何关于为什么这行得通但其他方式不行的提示吗?

标签: powershellwindows-10powershell-remoting

解决方案


推荐阅读