【发布时间】:2021-11-07 01:11:47
【问题描述】:
我正在尝试编写一个脚本,以便在一些连接在离线域中的远程服务器上远程安装一些 Windows 更新。
我已经尝试过常规的 PS Remoting,经过一些研究,我认为我正在尝试做的事情不受 Microsoft 的支持。检查我的事件日志时,我遇到了一堆这样的错误。
编辑
我想补充一点,我已尝试从本地计算机运行 .\Install2012R2.ps1 脚本,修改为在其中包含 Invoke-Command 并让它运行原始 Install2012R2.ps1 的更新部分,我会得到相同的结果错误。
我希望通过将脚本放置在每台服务器上,它会更喜欢它。
结束编辑
Windows update could not be installed because of error 2147942405 "Access is denied."
(Command line: ""C:\Windows\System32\wusa.exe" "C:\Updates\windows8.1-kb4556853-x64.msu" /quiet /norestart")
我尝试以服务器上管理员帐户的凭据运行Invoke-Command,但我一直没有运气,并且正在寻找一些建议,如果有人之前可能尝试过/做过此操作。
$Servers = @("V101-Test1","V101-Test2")
$Username = 'admin'
$Password = 'Password'#not actual password
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Get-PSSession | Remove-PSSession
New-PSSession -ComputerName $Servers
foreach($Server in $Servers){
Get-ChildItem -Path C:\Source\Temp -Recurse | Copy-Item -Destination "\\$Server\c$\Updates\" -Force
}
Invoke-Command $Servers -Credential $Cred -ScriptBlock{
& "C:\Updates\Install2012R2.ps1"
}
编辑 2
这是Install2012R2.ps1脚本的实际安装代码
$updatedir= "./"
$files = Get-ChildItem $updatedir -Recurse
$msus = $files | ? {$_.extension -eq ".msu"}
$exes = $files | ? {$_.extension -eq ".exe"}
foreach ($file in $msus){
$KBCtr++
$fullname = $file.fullname
# Need to wrap in quotes as folder path may contain space
$fullname = "`"" + $fullname + "`""
$KBN = $fullname.split('-')[1]
# Need to wrap in quotes as folder path may contain space
$fullname = "`"" + $fullname + "`""
# Specify the command line parameters for wusa.exe
$parameters = $fullname + " /quiet /norestart"
# Start services and pass in the parameters
$install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
$install.WaitForExit()
}
【问题讨论】:
-
Install2012R2.ps1是否连接到任何远程服务器?这将包括一个像\\server.domain.tld\ShareName$\somefile.ext这样的UNC路径上的东西。 -
不,它没有,它所做的只是收集所有 .msus 并尝试安装它们。 编辑我在最后的原帖中添加了
Install2012R2.ps1的实际安装信息 -
它从哪里收集 MSU?我没有看到你在运行调用命令之前复制它们,所以我认为它需要从某个地方拉它们?还是他们已经在
C:\Updates下的目标服务器上暂存? -
$updatedDir的价值从何而来? 什么$updatedDir的值是什么? -
我在后半部分添加了
$UpdatedDir变量。Install2012R2.ps1脚本驻留在服务器上,MSU 文件位于C:\Updates
标签: windows powershell windows-update