Thera 有很多关于使用 PowerShell 修补 Windows 的材料。还有一些关于远程修补的内容。
在为 SharePoint 优化/稳定补丁时,它们应该分批应用。
为了大大简化要应用的补丁的选择,我正在使用模块 PS Gallery - PSWindowsUpdate.
但是,SharePoint 的大部分补丁都必须以交互方式运行,这可以使用
Scheduled Tasks
。但这通常需要具有适当权限的用户已经在本地登录,这违背了远程脚本的目的:/
S4U
,为用户服务,应该绕过该要求。但是,我似乎找不到要使用的正确参数。
我确实认为
S4U
被阻止访问网络(尽管其他来源另有说明),所以我试图确保事先下载补丁。通过使用内置的 WindowsUpdateProvider
或 PSWindowsUpdate
.
运行计划任务的账号当然也需要系统权限
Logon as batch job
.
在我的案例中,可能会出现问题的一件事是必须在整个网络中禁用旧版 RPC。
Invoke-Command -ComputerName RemoteSrv -ScriptBlock {
$SoftwareUpdates = Start-WUScan -SearchCriteria "Type='Software' AND IsInstalled =0"
Install-WUUpdates -Updates $SoftwareUpdates -DownloadOnly $true | Out-Null
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddYears(10)
$Argument = "Install-WindowsUpdate -NoCategory 'Microsoft SQL Server','Office Online Server' -AcceptAll -AutoReboot"
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "$Argument"
$Principal = New-ScheduledTaskPrincipal `
-UserId 'domain\userid' `
-RunLevel Highest `
-LogonType S4U
Register-ScheduledTask `
-TaskPath '\SharePoint\' -TaskName 'PatchSharePoint' `
-Trigger $Trigger `
-Principal $Principal `
-Action $Action `
-Force | Out-Null
Start-ScheduledTask -TaskPath '\SharePoint\' -TaskName 'PatchSharePoint'
}
需要交互式登录的补丁仍然没有应用。以及 Tasck Scheduler 历史记录中的
Action Completed
。
Task Scheduler successfully completed task "\SharePoint\PatchSharePoint", instance "{...},
action "PowerShell.exe" with return code 2147942401.
翻译成
Illegal Function
。很明显,我把事情搞砸了。