Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
远程执行以使用powershell安装软件更新_Powershell - Fatal编程技术网

远程执行以使用powershell安装软件更新

远程执行以使用powershell安装软件更新,powershell,Powershell,我已经阅读了所有与此问题相关的可用问题和答案,但我尝试过的方法都是我尝试过的 这段代码位于我正在调用的模块内,如下所示: Invoke-Command -ScriptBlock {EnsurePowerShellV5 -WMF50Path "D:\wmf50"} @param $path = "D:\Win8.1AndW2K12R2-KB3134758-x64.msu" Invoke-Command -ScriptBlock { & "$($env:WINDIR)\system32\w

我已经阅读了所有与此问题相关的可用问题和答案,但我尝试过的方法都是我尝试过的

这段代码位于我正在调用的模块内,如下所示:

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" }
另一方面,我尝试:

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
}
使用详细信息时出现的错误

System.Management.Automation.RemoteException:[错误]PowerShell 5.0 没有检测到。请安装并重试。在 系统。管理。自动化。异常处理操作。检查操作首选项(FunctionContext funcContext,异常)位于 系统.管理.自动化.解释器.操作调用指令'2.运行(解释器框架 帧)在 系统。管理。自动化。解释器。EntertryCatch最终指令。运行(解释器框架 帧)在 系统。管理。自动化。解释器。EntertryCatch最终指令。运行(解释器框架 (框架)

你可以尝试使用。按照中的说明安装,然后尝试以下命令:

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


希望这能有所帮助。

哪个变量触发错误输出?我怀疑这会导致问题
$pinfo.Arguments=“$path/quiet”
,因为当我删除此变量时,进程正在启动,但没有执行我可以传递参数吗?