"invoke-command" using wusa.exe in powershell - won't install the msu

1

1

I'm attempting to push a windows hotfix to a number of computers on our network, using PowerShell v3. I've downloaded the appropriate .msu file, I've been able to successfully install it from the local machine on the command line, using:

wusa c:\temp\hotfixname.msu /quiet /norestart

The problem comes when I try to run it from powershell. We can assume that the msu is already on everyone's machine, at c:\temp\hotfixname.msu, and that PSRemoting is already enabled. Here's what I have more or less:

import-module ActiveDirectory

$AllPCs = Get-ADComputer -SearchBase "Appropriate OU Here" -filter *

$AllPCs | Foreach {
Invoke-Command -ComputerName "$($_.name)" -AsJob -ScriptBlock { 
        if (!(Get-HotFix -id hotfixkb)) { CMD /C "wusa.exe c:\temp\hotfixname.msu /quiet /norestart" }
    }
 }

When run like this from my own admin box, running powershell as admin, the local machine opens a wusa.exe process for a second or so, before it disappears. Nothing is installed.

I can run CMD /C "wusa.exe /?, and it does open the process (it hangs, but only because wusa opens its help in a GUI).

I'm out of ideas - does anyone have any advice on this? Is there something I'm missing?

bjscollura

Posted 2015-03-27T17:05:11.690

Reputation: 13

Answers

3

Since PSRemoting uses WinRM and according to this it doesn't look like you can use wusa.exe with WinRM or WinRS it doesn't look possible with the code you listed.

There is a workaround listed however:

Extract the .msu file through Windows Remote Shell with WUSA using the following command:

winrs.exe -r:%computername% wusa.exe %kb-update% /extract:%destination%

When complete, install the .cab package with dism.exe or Package Manager. To use dism.exe, use the command below:

winrs.exe -r:%computername% dism.exe /online /add-package /PackagePath:%Path_To_Package%\KBnnnnnnn.cab

Josh

Posted 2015-03-27T17:05:11.690

Reputation: 4 746

2We wound up running a scheduled task to force the local PC to run wusa.exe, which seemed to do the trick! – bjscollura – 2015-03-27T22:00:33.487

0

remote update of powershell from 3 -> 5.1 (windows7), through the WinRM interface and Ansible server - PSH update-psh.ps1 script (worked for me):

# install POWERSHELL update
# descr. wusa: https://support.microsoft.com/en-us/help/934307/description-of-the-windows-update-standalone-installer-in-windows
# descr. dism: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/dism-operating-system-package-servicing-command-line-options 

Start-Process -FilePath 'wusa.exe' -ArgumentList "C:\workit\updatePSH\Win7AndW2K8R2-KB3191566-x64.msu /extract:C:\workit\updatePSH" -Verb RunAs  -Wait -Passthru

Start-Sleep -Seconds 5

Start-Process -FilePath 'dism.exe' -ArgumentList "/online /add-package /PackagePath:C:\workit\updatePSH\WSUSSCAN.cab /PackagePath:C:\workit\updatePSH\Windows6.1-KB2809215-x64.cab /PackagePath:C:\workit\updatePSH\Windows6.1-KB2872035-x64.cab /PackagePath:C:\workit\updatePSH\Windows6.1-KB2872047-x64.cab /PackagePath:C:\workit\updatePSH\Windows6.1-KB3033929-x64.cab /PackagePath:C:\workit\updatePSH\Windows6.1-KB3191566-x64.cab /IgnoreCheck /quiet" -Verb RunAs -Wait -PassThru

tatan

Posted 2015-03-27T17:05:11.690

Reputation: 1

1please fix the formatting of your answer (no need for 'code' tag, just indent relevant lines with 4 spaces ...) – Pierre.Vriens – 2017-12-01T13:45:43.270