mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
21 lines
794 B
PowerShell
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
|