PSWindowsUpdate 在域管理员时在远程机器上被拒绝访问
PSWindowsUpdate gets Acces Denied on Remote Machienes while Domain Admin
我想将更新部署到我们域中的 Windows 服务器。
为此,我想使用模块“PSWindowsUpdate”Here is the Official Release。
我将此模块与 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 :
contains a list of server fqdns
任何想法或解决方案都会拯救我,
谢谢!
尼克
编辑 1:
这是错误消息:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
+ CategoryInfo : NotSpecified: (:) [Get-WindowsUpdate], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,PSWindowsUpdate.GetWindowsUpdate
+ PSComputerName : fs02.azubi.netz
这会破坏我的会话,但输出是 $true
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
Invoke-Command : Cannot bind parameter 'Session'. Cannot convert value "True" to type "System.Management.Automation.Runspaces.PSSession". ...
为了解决这个问题,我不得不改变复制到其他系统的方式和 get-windowsupdate 的实际调用。
Mooudle 必须在 $env:PSModPath 中,因此要修复它,您必须复制到其中一个文件夹中。
Copy-Item "$modpath$($Script:My.ModuleVersion)\" -Destination "$psmod\PSWindowsUpdate$($Script:My.ModuleVersion)" -ToSession $ses -Recurse -ErrorAction Stop
更新不需要运行调用命令。
Get-WindowsUpdate -AcceptAll -Install -IgnoreReboot -ComputerName $session.ComputerName
如果您遇到类似问题,希望这对您有所帮助!
我想将更新部署到我们域中的 Windows 服务器。 为此,我想使用模块“PSWindowsUpdate”Here is the Official Release。 我将此模块与 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 : contains a list of server fqdns
任何想法或解决方案都会拯救我, 谢谢!
尼克
编辑 1:
这是错误消息:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) + CategoryInfo : NotSpecified: (:) [Get-WindowsUpdate], UnauthorizedAccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,PSWindowsUpdate.GetWindowsUpdate + PSComputerName : fs02.azubi.netz
这会破坏我的会话,但输出是 $true
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
Invoke-Command : Cannot bind parameter 'Session'. Cannot convert value "True" to type "System.Management.Automation.Runspaces.PSSession". ...
为了解决这个问题,我不得不改变复制到其他系统的方式和 get-windowsupdate 的实际调用。
Mooudle 必须在 $env:PSModPath 中,因此要修复它,您必须复制到其中一个文件夹中。
Copy-Item "$modpath$($Script:My.ModuleVersion)\" -Destination "$psmod\PSWindowsUpdate$($Script:My.ModuleVersion)" -ToSession $ses -Recurse -ErrorAction Stop
更新不需要运行调用命令。
Get-WindowsUpdate -AcceptAll -Install -IgnoreReboot -ComputerName $session.ComputerName
如果您遇到类似问题,希望这对您有所帮助!