Files
sql-server-samples/samples/manage/DiscoverSql.ps1
T
2023-02-20 19:33:29 +00:00

21 lines
794 B
PowerShell

# This script checks if SQL Server is installed on Windows
[string] $SqlInstalled = ""
$regPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server'
if (Test-Path $regPath) {
$inst = (get-itemproperty $regPath).InstalledInstances
#$SqlInstalled = ($inst.Count -gt 0)
foreach ($i in $inst) {
# Read registry data
#
$p = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
$setupValues = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup")
$edition = ($setupValues.Edition -split ' ')[0]
$version = ($setupValues.Version)
$SqlInstalled = $version, $edition -join ':'
}
}
Write-Output $SqlInstalled