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

18,513

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

Share:
18,513

Related videos on Youtube

bjscollura
Author by

bjscollura

I'm a person with a computer and a Stack Overflow account.

Updated on September 18, 2022

Comments

  • bjscollura
    bjscollura over 1 year

    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?

  • Pierre.Vriens
    Pierre.Vriens over 6 years
    please fix the formatting of your answer (no need for 'code' tag, just indent relevant lines with 4 spaces ...)
  • Hydrargyrum
    Hydrargyrum almost 4 years
    On my copy of Win 10 v1607 and v1903, I get "The /extract option is no longer supported" when I try to run wusa.exe this way
  • Josh
    Josh almost 4 years
    @Hydrargyrum Try using expand -f:* myupdate.msu c:\myexpandloc