Determine SQL Version and Edition using Powershell and WMI

This small Powershell script prompts for a computername and tries to determine the installed version and edition of SQL using WMI.

$comp = Read-Host "Enter Computername:"
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement10 -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement12 -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement14 -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize

Leave a Reply