Commands / Test-sqmSqlInstanceInstalled
Other

Test-sqmSqlInstanceInstalled

Checks whether a SQL Server instance is installed on the local machine — combining a registry lookup (Instance Names\SQL) with a Windows service check (MSSQLSERVER / MSSQL$<Instance>). Purely read-only, no SQL connection required.

Module: sqmSQLTool
Requires: Local registry/service read access
ShouldProcess: No
Output: PSCustomObject

Execution Flow

START Read HKLM:\...\Instance Names\SQL for -InstanceName key Registry key found? IsInstalled=true read Version/Edition Get-Service MSSQLSERVER or MSSQL$<InstanceName> Service exists? ServiceState = NotFound ServiceState = Running/Stopped (also → IsInstalled=true) IsInstalled true? Status = Installed Status = NotInstalled Return PSCustomObject (Status, Version, Edition, ServiceState) DONE
A running Windows service counts as "installed" even without a matching registry entry (rare, but happens after partial uninstalls) — the two checks are OR'd together, not AND'd. This makes the function safe to use as a pre-flight gate before install/upgrade automation: if (-not (Test-sqmSqlInstanceInstalled).IsInstalled) { ... }.

Parameters

ParameterTypeRequiredDescription
-InstanceNameStringOptionalName of the SQL instance to check. Default: MSSQLSERVER (default instance).

Return Value

Returns a single PSCustomObject with: InstanceName, IsInstalled, Version, Edition, ServiceName, ServiceState (Running/Stopped/NotFound), Status (Installed, NotInstalled, or Error), Message.

Examples

Example 1 — Check the default instance

Test-sqmSqlInstanceInstalled

Example 2 — Check a named instance

Test-sqmSqlInstanceInstalled -InstanceName 'INST01'

Example 3 — Use as an install-automation gate

if ((Test-sqmSqlInstanceInstalled).IsInstalled) { Write-Host "SQL installiert" }