Find Database Type - Port - Remote Address.
With the below script Check-DatabaseStatus.ps1 you can executed and find what Database Type the Server is using also the Port where is listening and the Remote Address that is configure to listen.
🚀 One-Line Download & Execute :
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression (Invoke-WebRequest -Uri "https://docs.greenhome.stream/attachments/55" -UseBasicP) | Out-Null
📜 PowerShell Script
Save this script as Check-DatabaseStatus.ps1 and run it with PowerShell:
# Clear Screen
Clear-Host
# Set default database info
$foundDatabases = @()
$finalMessage = ""
# Function to write colored output
function Write-Color {
param (
[string]$Message,
[ConsoleColor]$Color = "White"
)
Write-Host $Message -ForegroundColor $Color
}
# Function to check service and port
function Check-Database {
param (
[string]$Name,
[string]$ServiceNamePattern,
[int]$DefaultPort
)
Write-Color "Searching for $Name Database..." -Color DarkYellow
$service = Get-Service | Where-Object { $_.Name -like "*$ServiceNamePattern*" -and $_.Status -eq "Running" }
if ($service) {
Write-Color "$Name Database Found." -Color Green
$foundDatabases += $Name
# Leave empty line
Write-Host ""
Write-Color "Searching for Port where database are listening by default..." -Color DarkYellow
$connection = Get-NetTCPConnection -LocalPort $DefaultPort -State Listen -ErrorAction SilentlyContinue
if ($connection) {
$port = $connection.LocalPort
$remote = $connection.LocalAddress
Write-Color "Found Database listening at port : $port" -Color Green
Write-Color "For Remote Address : $remote" -Color Green
$finalMessage += "Found Database: $Name`nListen on Port: $port`nRemote Address: $remote`n`n"
}
else {
Write-Color "$Name is running, but not listening on expected port $DefaultPort." -Color Red
}
}
else {
Write-Color "$Name Database NOT Found." -Color Red
}
# Leave empty line
Write-Host ""
}
# Check MSSQL
Check-Database -Name "MSSQL" -ServiceNamePattern "sql" -DefaultPort 1433
# Check MySQL
Check-Database -Name "MySQL" -ServiceNamePattern "mysql" -DefaultPort 3306
# Show final message box
Add-Type -AssemblyName PresentationFramework
if ($foundDatabases.Count -gt 0) {
[System.Windows.MessageBox]::Show($finalMessage.Trim(), "Database Check Result", "OK", "Information")
} else {
[System.Windows.MessageBox]::Show("NO Database Found.!", "Database Check Result", "OK", "Warning")
}
✅ Script Features
-
Clears the screen.
-
Searches for MSSQL and MySQL services.
-
Checks default listening ports: 1433 (MSSQL) and 3306 (MySQL).
-
Displays results in color-coded output.
-
Shows a Windows message box with the final result.