PSWindowsUpdate 在域管理员期间在远程机器上被拒绝访问

问题描述 投票:0回答:1

我想将更新部署到我们域中的 Windows 服务器。 为了实现这一目标,我想使用模块“PSWindowsUpdate”这里是官方版本。 我将此模块与 PSSessions 结合使用,并将其本地导入到默认模块路径之外的所有服务器上。

它应该接受更新并安装它们而无需重新启动。该脚本是使用域管理员运行的

接受更新后,它应该开始下载发生这种情况的地方:The Error of the Job

安装 2018 年 7 月安全补丁后,我开始收到此错误。

由于公司原因,我无法共享所有代码,以下是重要的部分:

function invokeUpdate{
param(
    $session
)
if($Script:My.Reboot.isChecked){
    $job = Invoke-Command -Session $session -ScriptBlock {Import-Module "C:\Scripts\updateModule\$($Using:My.ModuleVersion)\PSWindowsUpdate"; get-windowsupdate -install -AcceptAll} -AsJob
}else {
    $job = Invoke-Command -Session $session -ScriptBlock {Import-Module "C:\Scripts\updateModule\$($Using:My.ModuleVersion)\PSWindowsUpdate"; get-windowsupdate -install -ignoreReboot -AcceptAll} -AsJob
    }
return $job
}

function initSession{
param(
    $serverHostname
)
$ses = New-PSSession -Computername $serverHostname
if(!(Invoke-Command -Session $ses -ScriptBlock {Test-Path "C:\Scripts\updateModule\" })){
    Copy-Item "$modpath\$($Script:My.ModuleVersion)" -Destination "C:\Scripts\updateModule\$($Script:My.ModuleVersion)" -ToSession $ses -Recurse
}
Invoke-Command -Session $ses -ScriptBlock {
    if((Get-ChildItem -Path "C:\Scripts\updateModule\").count -gt 1){
        Get-ChildItem | Where-Object Name -NotLike "$($Using:My.ModuleVersion)" | Remove-Item -Recurse -Force
    }
}
return $ses
}

$sessions =  [System.Collections.ArrayList]@()
$Script:My.ModuleVersion = "2.1.1.2"
foreach  ( $server in $Script:My.ServerActive.Items){
    $sessions.Add(  (initSession -serverHostname $server) )
}
foreach ($ses in $sessions){
   invokeUpdate -session $ses
}

$Script:My.ServerActive.Items: 包含服务器 fqdn 列表

任何想法或解决方案都会拯救我, 谢谢!

尼克

编辑1:

这是错误消息:

访问被拒绝。 (HRESULT 异常:0x80070005 (E_ACCESSDENIED)) + 类别信息:未指定:(:) [获取 WindowsUpdate]、UnauthorizedAccessException +FullyQualifiedErrorId:System.UnauthorizedAccessException,PSWindowsUpdate.GetWindowsUpdate + PS计算机名称:fs02.azubi.netz

这会破坏我的会话,但输出是 $true

([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")

Invoke-Command:无法绑定参数“会话”。无法将值“True”转换为类型“System.Management.Automation.Runspaces.PSSession”。 ...

powershell windows-update
1个回答
0
投票

要解决此问题,我必须更改复制到其他系统的方式以及 get-windowsupdate 的实际调用。

Mooudle 必须位于 $env:PSModPath 中,因此要修复它,您必须复制到这些文件夹之一。

Copy-Item "$modpath\$($Script:My.ModuleVersion)\" -Destination "$psmod\PSWindowsUpdate\$($Script:My.ModuleVersion)" -ToSession $ses -Recurse -ErrorAction Stop 

更新不需要运行 Over Invoke Command。

Get-WindowsUpdate -AcceptAll -Install  -IgnoreReboot -ComputerName $session.ComputerName

如果您遇到类似问题,希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.