powershell - 如何在会话之外与远程机器交互?
问题描述
我想在我的一些域计算机上静默安装软件。由于这些软件包不是以 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
另一方面,这非常有效。你可以给我任何关于为什么这行得通但其他方式不行的提示吗?
解决方案
推荐阅读
- python - Compare two string char by char in python and get unmatched character
- java - How to update Springboot application to use SSL/TLS certificates to connect to RDS?
- python - Discord bot 不工作且不改变状态
- c# - Entity Framework Core 5: configuring many to many relationships, how to specify foreign key names
- python-3.x - 由于超出字符串中的字符限制而导致的运行时错误
- java - 如何按字母对Java中的对象数组进行排序
- django - Django 模型数据库查询优化(使用 select_related / prefetch_related)
- amazon-web-services - 将文件从 aws EC2 实例复制到 hadoop 集群时出错
- html - 如何仅使用 1 个 HTML 标签制作纯 CSS parellogram 按钮?
- html - 为 html 导入 Tumblr 帖子内容