Fix CED ConfigMgr notification connectivity and verify online status

This commit is contained in:
alexrg committed 2026-10-01 10:30:18 -06:00
1 parent 46c0be732a
commit 11d49dc245
3 files changed
+80 -3

No files matched your search

+21 -3
View File
@@ -3,12 +3,30 @@ param(
[Parameter(Mandatory)][PSCredential]$Credential,
[string]$TargetOuDn = 'OU=Centro de Experiencia Digital,OU=Laboratorio,DC=lci,DC=lasalle,DC=mx',
[string]$Ssid = 'Centro de Experiencia Digital',
[ValidatePattern('^[A-Za-z0-9]{3}$')][string]$SiteCode = 'LCI',
[string]$WacThumbprint = 'CF2B7C6899885BF9EB0E59054F8E8AB2D4390513'
)
$ErrorActionPreference = 'Stop'
Import-Module ActiveDirectory
Clear-DnsClientCache
$computers = @(Get-ADComputer -SearchBase $TargetOuDn -Filter 'Enabled -eq $true' -Properties DNSHostName)
$notification = @{}
$notificationError = $null
try {
foreach ($resource in (Get-CimInstance -Namespace ("root\SMS\site_"+$SiteCode) -ClassName SMS_CombinedDeviceResources)) {
$notification[$resource.Name] = $resource
}
} catch { $notificationError = $_.Exception.Message }
function Add-NotificationStatus($result) {
$resource = $notification[$result.Name]
# Null means no provider data, not a confirmed offline client.
$result | Add-Member -NotePropertyMembers @{
NotificationOnline = $(if ($resource) { $resource.CNIsOnline } else { $null })
NotificationMP = $(if ($resource) { $resource.CNAccessMP } else { $null })
NotificationLastOnlineTime = $(if ($resource) { $resource.CNLastOnlineTime } else { $null })
NotificationQueryError = $notificationError
} -PassThru
}
$online = @()
foreach ($computer in $computers) {
$client = [Net.Sockets.TcpClient]::new()
@@ -17,7 +35,7 @@ foreach ($computer in $computers) {
$available = $connect.AsyncWaitHandle.WaitOne(1000) -and $client.Connected
} catch { $available = $false } finally { $client.Dispose() }
if ($available) { $online += $computer.DNSHostName }
else { [pscustomobject]@{Name=$computer.Name;Reachable=$false;WifiConnected=$false;ClientRunning=$false;Error='No WinRM TCP connection at current DNS address.'} }
else { Add-NotificationStatus ([pscustomobject]@{Name=$computer.Name;Reachable=$false;WifiConnected=$false;ClientRunning=$false;Error='No WinRM TCP connection at current DNS address.'}) }
}
$options = New-PSSessionOption -OpenTimeout 10000 -OperationTimeout 60000
if ($online.Count) {
@@ -46,10 +64,10 @@ if ($online.Count) {
WacRootTrusted=(Test-Path ("Cert:\LocalMachine\Root\"+$thumbprint));Error=$null
}
})
$reported
foreach ($result in $reported) { Add-NotificationStatus $result }
foreach ($hostname in $online) {
if ($reported.PSComputerName -inotcontains $hostname) {
[pscustomobject]@{Name=$hostname.Split('.')[0];Reachable=$false;WifiConnected=$false;ClientRunning=$false;Error='WinRM session or client verification failed after TCP probe.'}
Add-NotificationStatus ([pscustomobject]@{Name=$hostname.Split('.')[0];Reachable=$false;WifiConnected=$false;ClientRunning=$false;Error='WinRM session or client verification failed after TCP probe.'})
}
}
}