Execution Flow
If the SQL Browser (UDP 1434) is unreachable — common when only TCP is opened in the firewall — the function falls back to whatever
-Port was given (default 1433) and logs a warning, rather than failing outright. This means "Failed" for a named instance can mean either "TCP port blocked" or "SQL Browser blocked and the fallback port also happens to be wrong" — check DynamicPort in the result to tell them apart.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -Server | String[] | Required | Hostname(s) or IP(s) to test. Pipeline-capable. |
| -Port | Int (1–65535) | Optional | TCP port to test. Default: 1433. Ignored when -Instance is given and the SQL Browser returns a dynamic port. |
| -Instance | String | Optional | Named instance to resolve via SQL Browser (UDP 1434) before testing TCP. |
| -TimeoutSeconds | Int (1–60) | Optional | TCP connection timeout. Default: 5. |
| -ContinueOnError | Switch | Optional | Continue with the next server on error instead of aborting the whole run. |
| -EnableException | Switch | Optional | Throw exceptions immediately (overrides -ContinueOnError). |
Return Value
Returns a PSCustomObject[] — one entry per server — with: Server, Port, Instance, DynamicPort (bool), TcpReachable (bool), Status (OK, Failed, or Error), Message.
Examples
Example 1 — Test the default instance on port 1433
Test-sqmSQLFirewall -Server "SQL01"Example 2 — Test a custom port
Test-sqmSQLFirewall -Server "SQL01" -Port 54321Example 3 — Resolve and test a named instance's dynamic port
Test-sqmSQLFirewall -Server "SQL01" -Instance "SAGE"Example 4 — Sweep a server list via pipeline
"SQL01","SQL02","SQL03" | Test-sqmSQLFirewall -Instance "PROD" -TimeoutSeconds 3