Hi,
Here's a PowerShell script that uses the PortQry command-line tool to check the availability of UDP ports and integrates with SCOM to create a custom monitor.
This script will check the status of UDP ports 53 and 123 on your Domain Controllers and generate alerts if the ports are not accessible.
- Download PortQry:
- Ensure you have the PortQry tool downloaded and extracted to a directory on your server.
- Create the PowerShell Script:
- Save the following script as
Check-UDPPorts.ps1
:
- Save the following script as
param (
[string]$Server,
[int]$Port
)
$portQryPath = "C:\Path\To\PortQry.exe" # Update this path to where PortQry is located
function Test-UDPPort {
param (
[string]$Server,
[int]$Port
)
$result = & $portQryPath -n $Server -p udp -e $Port
if ($result -match "LISTENING") {
return $true
} else {
return $false
}
}
$ports = @(53, 123)
$allPortsOpen = $true
foreach ($port in $ports) {
if (-not (Test-UDPPort -Server $Server -Port $port)) {
$allPortsOpen = $false
Write-Output "Port $port is not open on $Server"
} else {
Write-Output "Port $port is open on $Server"
}
}
if ($allPortsOpen) {
exit 0 # All ports are open
} else {
exit 1 # One or more ports are not open
}
- Create a SCOM Monitor:
- Open the SCOM Console.
- Navigate to Authoring > Monitors > Create a Monitor > Unit Monitor.
- Select Scripting > Generic > Sample PowerShell Script 2 State Monitor.
- Choose the appropriate management pack or create a new one.
- Configure the monitor to target your Domain Controllers.
- Set the script path to the location of
Check-UDPPorts.ps1
. - Configure the parameters to pass the server name and ports to the script.
- Set the script to run at regular intervals and configure the alerting conditions based on the script's exit code.
This setup will allow you to monitor the availability of UDP ports 53 and 123 on your Domain Controllers using SCOM and receive alerts if any issues are detected.
If you need further assistance or have any questions, feel free to ask! 😊