【问题标题】:Invoke-Command doesn't launch the executable on a remote workstationInvoke-Command 不会在远程工作站上启动可执行文件
【发布时间】:2019-09-27 11:29:48
【问题描述】:

我正在尝试在我的 Active Directory 中的所有工作站上卸载 MS Office 2007。为此,我必须启动由UninstallConfig.xml 文件配置的C:\Transfer2007\setup.exe 以进行静默卸载(位于同一目录中)。 PowerShell 的Invoke-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

【问题讨论】:

    标签: powershell active-directory executable uac invoke-command


    【解决方案1】:

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

    【讨论】:

    • 这似乎只能部分起作用。执行脚本时,我可以看到 MS Office 仍然安装在控制面板中。但是我无法运行它。重新启动没有帮助。所以这可能不是一种干净的卸载方式
    • 好的。尝试这个。 --- Invoke-Command -ComputerName server01 -ScriptBlock { Start-Process 'C:\Transfer2007\SETUP.exe' -ArgumentList '/uninstall ProPlus /config \UninstallConfig.xml' -Wait } -Credential mmb -ComputerName $Computer -AsJob
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    相关资源
    最近更新 更多