我有一个有效的 PowerShell 脚本,用于安装当前显示可在 SCCM 客户端中安装的任何补丁,但我发现无法构建一个纠缠测试来验证脚本是否按预期工作而无需实际安装补丁。
是否有一个虚拟补丁以某种方式创建、安装、测试,然后在纠缠测试结束时卸载?我不知道这是否可能。
安装可用补丁的脚本:
Function Install-SCCMAvailablePatches {
[CmdletBinding()]
param(
[Parameter(
Mandatory = $False,
ValueFromPipelineByPropertyName = $True,
HelpMessage = "Reboot Server if needed? Default: True")]
[ValidateNotNullOrEmpty()]
[string]
$Reboot = $True
)
begin {
Write-Verbose "Install-SCCMAvailablePatches: Started"
}
process {
try { ([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates([System.Management.ManagementObject[]] (Get-WmiObject -Query 'SELECT * FROM CCM_SoftwareUpdate' -namespace 'ROOT\ccm\ClientSDK'))
while (Not((Get-WmiObject -Namespace 'ROOT\ccm\ClientSDK' -Class 'CCM_ClientUtilities' -list).DetermineIfRebootPending().RebootPending)) {
$Time = (get-date).ToShortTimeString()
Write-Verbose "Still Patching @ $Time"
Start-Sleep -s 60 }
if ($Reboot -eq $True) {
if ((Get-WmiObject -Namespace 'ROOT\ccm\ClientSDK' -Class 'CCM_ClientUtilities' -list).DetermineIfRebootPending().RebootPending) {
(Get-WmiObject -Namespace 'ROOT\ccm\ClientSDK' -Class 'CCM_ClientUtilities' -list).RestartComputer()
}
}
}
catch {
Write-Error -Message "Something went wrong with Install-SCCMAvailablePatches."
}
}
end {
Write-Verbose "Install-SCCMAvailablePatches: Completed"
}
} #End Install-SCCMAvailablePatches