首页 > 解决方案 > Invoke-Command 不会在远程工作站上启动可执行文件

问题描述

我正在尝试在我的 Active Directory 中的所有工作站上卸载 MS Office 2007。为此,我必须启动C:\Transfer2007\setup.exeUninstallConfig.xml文件配置的静默卸载(位于同一目录中)。PowerShellInvoke-Command不会返回任何错误,并且似乎一切都很好,但setup.exe从未在目标工作站上启动。

当我手动启动 setup.exe 时,我收到“打开文件 - 安全警告”,我必须按“启动”。在下一步中,我被要求提供管理员访问权限 (UAC)。我认为这些弹出窗口是为什么 .exe 在尝试通过 PowerShell 远程运行时从不启动的问题。

我已经尝试在代码中包含以下内容:

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

标签: powershellactive-directoryexecutableuacinvoke-command

解决方案


尝试执行这个 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

推荐阅读