Задача определить какие сервера в ad требуют перезагрузку Pending Reboot. Прежде чем добавлять их в группу по плановой перезагрузке. Так как при назначении deploy прежде чем будет установлено обновление сервер перезагрузиться вне окна обслуживания .
Через базу sccm
SELECT [Name]
,[ClientState]
,"Pending Reboot"=
case [ClientState]
when '1' then 'Configuration Manager'
when '2' then 'File Rename'
when '3' then 'Configuration Manager, File Rename'
when '4' then 'Windows Update'
when '5' then 'Configuration Manager, Windows Update'
when '6' then 'File Rename, Windows Update'
when '7' then 'Configuration Manager, File Rename, Windows Update'
when '8' then 'Add or Remove Feature'
when '9' then 'Configuration Manager, Add or Remove Feature'
when '10' then 'File Rename, Add or Remove Feature'
when '11' then 'Configuration Manager, File Rename, Add or Remove Feature'
when '12' then 'Windows Update, Add or Remove Feature'
when '13' then 'Configuration Manager, Windows Update, Add or Remove Feature'
when '14' then 'File Rename, Windows Update, Add or Remove Feature'
when '15' then 'Configuration Manager, File Rename, Windows Update, Add or Remove Feature'
else 'Unknown'
end
FROM [v_CombinedDeviceResources]
where ClientState <> '0' and [Name] like '%MSK-%'
order by Name
Создать коллекцию в sccm
select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System join sms_combineddeviceresources comb on comb.resourceid = sms_r_system.resourceid where comb.clientstate <> 0
И с помощью PowerShell
# Замените эту строку путем указания пути к OU, в которой вы хотите выполнить поиск серверов
$ouPath = "OU=Servers,DC=adminbd,DC=ru"
# Получите список серверов из указанной OU
$servers = Get-ADComputer -SearchBase $ouPath -Filter {OperatingSystem -like "Windows Server*"}
$results = @() # Создайте массив для хранения результатов
foreach ($server in $servers) {
$MachineName = $server.Name
$RebootFlags = @{
Component_Based_Servicing = $null
Auto_Update = $null
Pending_System_Rename = $null
UpdateExeVolatile = $null
WMI_DetermineIfRebootPending = $null
}
Try {
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $MachineName)
$RebootFlags.Component_Based_Servicing = $Reg.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending') -ne $null
$RebootFlags.Auto_Update = $Reg.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') -ne $null
$RebootFlags.Pending_System_Rename = $Reg.OpenSubKey('SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName').GetValue('ComputerName') -ne $Reg.OpenSubKey('SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName').GetValue('ComputerName')
$RebootFlags.UpdateExeVolatile = $(IF ($Reg.OpenSubKey('SOFTWARE\Microsoft\Updates') -ne $null)
{ [INT]$Reg.OpenSubKey('SOFTWARE\Microsoft\Updates').GetValue('UpdateExeVolatile') -ne 0
} else { $False }
)
$RebootFlags.WMI_DetermineIfRebootPending = (Invoke-WmiMethod -ComputerName $MachineName -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -Name DetermineIfRebootPending -ErrorAction SilentlyContinue).RebootPending
} catch {
Write-Host "Failed to connect to $MachineName. Error: $_"
}
$RebootRequired = $false
$RebootReasons = @()
$RebootFlags.GetEnumerator() | foreach {
if ($_.Value -and $_.Key -ne "WMI_DetermineIfRebootPending") {
$RebootRequired = $true
$RebootReasons += $_.Key
}
}
$result = [pscustomobject]@{
"ComputerName" = $MachineName
"RebootRequired" = $RebootRequired
"RebootReasons" = $RebootReasons -join ', '
}
$results += $result
}
# Сохраните результаты в CSV с кодировкой UTF-8
$results | Export-Csv -Path "c:\RebootStatus.csv" -Encoding UTF8 -NoTypeInformation
Similar Posts:
- Как поменять на hp ilo 3 сеть через windows 2008 если не открывается HP Lights-Out Online Configuration Utility
- Установка диспетчера виртуальных машин System Center 2016 – шаг за шагом (руководство по быстрому запуску)
- Как найти где в AD на серверах включен smbv1 и smbv2
- Как сделать программный рейд зеркало на загрузочном диски windows 2022
- sp_configure