powershell - Invoke-Command 不会在远程工作站上启动可执行文件
问题描述
我正在尝试在我的 Active Directory 中的所有工作站上卸载 MS Office 2007。为此,我必须启动C:\Transfer2007\setup.exe
由UninstallConfig.xml
文件配置的静默卸载(位于同一目录中)。PowerShellInvoke-Command
不会返回任何错误,并且似乎一切都很好,但setup.exe
从未在目标工作站上启动。
当我手动启动 setup.exe 时,我收到“打开文件 - 安全警告”,我必须按“启动”。在下一步中,我被要求提供管理员访问权限 (UAC)。我认为这些弹出窗口是为什么 .exe 在尝试通过 PowerShell 远程运行时从不启动的问题。
我已经尝试在代码中包含以下内容:
–ExecutionPolicy Bypass
-Credential
具有管理员权限的参数
UninstallationConfig.xml
文件:
<Configuration Product="ProPlus">
<Display Level="none" CompletionNotice="no" />
<SettingId="SETUP_REBOOT" Value="AutoAlways" />
</Configuration>
PowerShell代码:
Invoke-Command -ScriptBlock {
Set-Location "C:\Transfer2007\";
.\SETUP.exe /uninstall ProPlus /config \UninstallConfig.xml
} -Credential mmb -ComputerName $Computer -AsJob
解决方案
尝试执行这个 ScriptBlock
$app = Get-WmiObject -Class Win32_Product |
Where-Object {$_.Name -match "Office"}
$app.Uninstall()
或者
Invoke-Command -ComputerName server01 -ScriptBlock {
Start-Process 'C:\Transfer2007\SETUP.exe' -ArgumentList '/uninstall ProPlus /config \UninstallConfig.xml' -Wait
} -Credential (Get-Credential 'localhost\Administrator') -ComputerName $Computer -AsJob
推荐阅读
- tomcat - 在 Tomcat7 或 Tomcat8 中,限制请求超时的最佳方法是什么?
- angularjs - Firebase/Firestore 未返回所有结果
- java - Okta/Spring Boot Saml 应用程序进入无限循环
- elasticsearch - 如何向 Elastic Search 建议添加“上下文”
- r - 使用R按日期分组后获取变量集的平均值
- android - jwplayer android 直播搜索栏未显示
- enums - @Enumerated(EnumType.STRING) 生成 int 列而不是 varchar
- dotnetnuke - 在 DNN 9 中添加视频
- c++ - 在构造函数中设置变量失败?
- c# - C# ClientWebsocket 在传入的二进制消息上抛出异常