从 PowerShell 在远程计算机上安装 .exe
因此,我一直在尝试通过 PowerShell 脚本执行以下操作:
对于计算机列表,请执行以下操作:
- Ping 计算机(通过 WMI)以查看其是否可用;如果没有,记录 &如果是这样,请继续在
- C:\ 驱动器的根目录上创建一个文件夹(通过 Invoke-WmiMethod);如果失败,记录 &中断,如果成功,则继续将
- 文件(包括 .exe)从另一台计算机复制到该文件夹中;如果失败,记录 &中断,如果成功,继续
- 运行.exe文件(通过Invoke-WmiMethod);如果失败,记录 &中断,如果成功,则记录成功,完成(使用这台计算机)。
我遇到的问题是 .exe(程序安装程序)的执行 - Invoke-WmiMethod 命令通常有效,但对于某些计算机,它会挂起(不是失败,而是挂起。)我尝试了一大堆东西来尝试让它作为一项作业运行,这样我就可以在安装上设置超时(运行 Invoke-WmiMethod
命令和-AsJob
参数,始终返回失败
...;Start-Job -Computer $compname { Invoke-WmiMethod...
,返回>已完成
,但安装从未发生;确保远程计算机已禁用 Windows 防火墙、关闭 UAC 等,但如果我在其上运行 Invoke-WmiMethod
命令,则不会运行作为一份工作,它是的,我正在以域管理员身份运行 PS,所以我应该拥有目标计算机的权限。)
因此,作为 PowerShell 的新手,我现在完全不知道接下来要尝试什么。 ..您将如何解决从 PowerShell 脚本在远程系统上运行 .exe 的问题?需要注意的是,目标计算机并不都运行 PowerShell [V1|V2](目标 PC 是 XP、Vista 和 7 的混合体)或者没有启用远程处理。另一个需要注意的是,安装程序是 .exe,而不是 .msi,并且无法更改(它是第三方应用程序)。
提前感谢任何可以在此处为我指明正确方向的人(以及给我一些示例代码...)
So, I have been trying to do the following via a PowerShell script:
For a list of computers, do:
- Ping the computer (via WMI) to see if it's available; if not, log & break, if so, continue on
- Create a folder on the root of the C:\ drive (via Invoke-WmiMethod); if fails, log & break, if successful, continue on
- Copy files (includes an .exe) from another machine into that folder; if fails, log & break, if successful, continue on
- Run the .exe file (via Invoke-WmiMethod); if fails, log & break, if successful, log success, done (with this computer.)
The problem I'm running into is the execution of the .exe (program installer) -- the Invoke-WmiMethod command usually works, but for some machines, it hangs (not fails, but hangs.) I've tried a whole bunch of stuff to try to get it to run as a job so I can set a timeout on the install (running the Invoke-WmiMethod
command with -AsJob
param, always returns Failed
...; Start-Job -Computer $compname { Invoke-WmiMethod...
, returns Completed
but the install never happens; making sure the remote machines have Windows Firewall disabled, UAC turned off, etc. but still if I run the Invoke-WmiMethod
command on them, not running as a job, it hangs. And yes, I'm running PS as a Domain Admin, so I should have rights on the target machines.)
So being a newb at all things PowerShell, I'm now at a complete loss as to what to try next... How would you tackle running a .exe on a remote system from a PowerShell script? One caveat is that the target machines don't all run PowerShell [V1|V2] (target PCs are a mix of XP, Vista and 7) or don't have remoting enabled. The other caveat being that the installer is an .exe, and not an .msi, and this can't be changed (it's a third-party app.)
Thanks in advance to anyone who can point me in the right direction here (and give me some sample code...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行这些脚本的系统(管理站或中央系统)上正在运行什么操作系统?如果是 Windows XP,WMI 和 -asJob 存在一个已知问题。
检查这个:WMI 查询脚本作为作业
在这种情况下,我建议迁移到 Windows 7 系统,然后运行脚本在所有其他计算机上远程安装 .exe。
What OS is running on the system (management station or central system) where these scripts are getting executed? If Windows XP, there is a known issue with WMI and -asJob.
Check this: WMI Query Script as a Job
In such a case, I'd suggest moving to a Windows 7 system and then run the script to remotely install .exe on all other machines.