0
votes

I have gone through all the available questions and answers related to this question but what ever ways I tried I didn't get the required here is what I tried,

The piece of code is inside a module which I am invoking as follows:

Invoke-Command -ScriptBlock {EnsurePowerShellV5 -WMF50Path "D:\wmf50"} @param

$path = "D:\Win8.1AndW2K12R2-KB3134758-x64.msu"
Invoke-Command -ScriptBlock { & "$($env:WINDIR)\system32\wusa.exe" /c "$path /qn" }

Other way I tried:

Invoke-Command -ScriptBlock {
  $pinfo = New-Object System.Diagnostics.ProcessStartInfo
  $pinfo.FileName = "$($env:WINDIR)\system32\wusa.exe"
  $pinfo.RedirectStandardError = $true
  $pinfo.RedirectStandardOutput = $true
  $pinfo.UseShellExecute = $false
  $pinfo.Arguments = "$path /quiet"

  $p = New-Object System.Diagnostics.Process
  $p.StartInfo = $pinfo
  $p.Start() 
  $p.WaitForExit()
  $stdout = $p.StandardOutput.ReadToEnd()
  $stderr = $p.StandardError.ReadToEnd()

  Write-Verbose $stderr
  Write-Verbose $stdout
}

Error I am getting when I use verbose

System.Management.Automation.RemoteException: [ERROR] PowerShell 5.0 was not detected. Please install it and try again. at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

1
Which variant triggers the error output? - Moerwald
I doubt this is causing issue $pinfo.Arguments = "$path /quiet" because when I remove this the process is getting started but not executing - Developer

1 Answers

0
votes

You can try to use PSWindowsUpdate. Install it as described on PowerShell Gallery, and try the command:

$WUInstallScript = { Import-Module C:\Path\PSWindowsUpdate.psm1; Get-WUInstall -AcceptAll -AutoReboot}
Invoke-WUInstall -ComputerName $hostname -Script $WUInstallScript

See also this link.

Hope that helps.