从 Powershell 执行远程静默 MSI 安装
我正在尝试使用 Invoke-Command powershell cmdlet 来安装 MSI 安装程序。从本地计算机上的 powershell 内和正确的目录中,可以执行以下操作:
./setup /quiet
以下似乎不起作用:
<前><代码>$脚本= { 参数($路径) cd“$路径” & ./设置/安静 返回密码 } 返回 Invoke-Command -ComputerName $product.IPs -ScriptBlock $script -Args $sourcePath
出于测试目的,我正在本地计算机上传递“.”。对于 -ComputerName 参数。在传递到 Invoke-Command 之前,已验证路径是否正确,并且在此代码的不同版本上生成的错误表明路径是正确的。我还尝试过在远程调用设置时使用或不使用“&”。其他 Invoke-Command 调用正在运行,所以我怀疑这是权限问题。我已经验证 pwd 调用的返回是预期的目录。
如何让安装生效?
I am trying to use the Invoke-Command powershell cmdlet to install a MSI installer. From within powershell on the local machine and from the proper directory, the following works:
./setup /quiet
The following does not seem to work:
$script = { param($path) cd "$path" & ./setup /quiet return pwd } return Invoke-Command -ComputerName $product.IPs -ScriptBlock $script -Args $sourcePath
For test purposes I am working on the local machine passing in "." for the -ComputerName argument. The paths have been verified correct before passing in to Invoke-Command, and errors generated on different versions of this code indicate the paths are correct. I have also tried with and without the "& " on the remote call to setup. Other Invoke-Command calls are working, so I doubt it is a permissions issue. I have verified that the return from the pwd call is the expected directory.
How do I get the install to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您收到什么错误(如果有)?不幸的是,您必须在本地计算机上以管理员身份运行 shell,才能使用 invoke-command 或任何需要管理权限的基于 WINRM 的命令连接到本地计算机(远程连接时不需要这样做)。
当连接到环回时,我相信它无法(出于某些安全原因)枚举组并确定您是否位于启用管理员的 AD 或本地组中,这就是它在远程计算机上调用时自动提升的方式。唯一的解决方案可能是使用一个条件来检查 localhost,如果是这样,请不要使用
-ComputerName
参数。此 GitHub 问题涵盖了它
What error (if any) are you receiving? Unfortunately, you must run the shell as admin on your local machine to be able to connect to your local machine with invoke-command or any WINRM based command that requires administrative privilege (this is not a requirement when connecting remotely).
When connecting to loopback, I believe it is unable (for some security reason) to enumerate groups and determine if you are in an admin enabled AD or local group, which is how it auto elevates when invoking on a remote machine. The only solution may be to have a conditional which checks for localhost and if so, don't use the
-ComputerName
parameter.This GitHub Issue covers it
您可以尝试在脚本块中使用 Start-Process:
cd $path
start-process setup.exe -arg "/quiet"
不确定您是否想要或需要等待。查看启动进程的帮助。
You might try using Start-Process in your script block:
cd $path
start-process setup.exe -arg "/quiet"
Not sure if you will want or need to wait. Look at help for Start-Process.
尝试在本地计算机上远程执行脚本时,我遇到了奇怪的问题。换句话说,远程powershell到本地机器。它返回一个错误,似乎表明计算机上未启用 PowerShell 远程处理,但事实确实如此。我可以从另一台机器远程运行脚本到目标,但是当使用远程处理到同一台机器时,问题就会出现。
Enable-PSRemoting -force
中所示。Set-ExecutionPolicy Unrestricted
中所示。如果策略设置为RemoteSigned
,这可能就是问题所在。您可能还想验证运行脚本的用户(在本地,但使用远程处理)是否具有“作为服务登录”或作为批处理作业的权限。只是猜测,如果上面的列表不能解决任何问题。
I have had weird issues when trying to remotely execute a script on a local machine. In other words, remote powershell to the local machine. It comes back with an error that seems to say that PowerShell remoting is not enabled on the machine, but it was. I can run the script remotely from another machine to the target, but when using remoting to the same box, the issue crops up.
Enable-PSRemoting -force
.Set-ExecutionPolicy Unrestricted
, for example. If the policy was set toRemoteSigned
, this might be the problem.You might also want to verify the user you are running the script as (locally, but using remoting) has privileges to "log on as a service" or as a batch job. Just guessing there, if the above list doesn't solve anything.