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)
$pinfo.Arguments = "$path /quiet"
because when I remove this the process is getting started but not executing - Developer