-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQLVersionCheck.ps1
67 lines (46 loc) · 2.51 KB
/
SQLVersionCheck.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Param(
[Parameter (Mandatory=$true,ValuefromPipeline=$true)]
[string []]$computername,
[string]$errorlogpath ='c:\temp\sql_check_error.log'
)
begin{
$host.UI.RawUI.WindowTitle = "SQL Version Check"
$starttime =Get-Date
Write-host "script start time $starttime " -ForegroundColor yellow |ft -AutoSize
}
process{
foreach ($computer in $computername) {
Write-Verbose "about to query $computer"
try {
$who = Get-WMIObject Win32_ComputerSystem -computername $computer| Select-Object -ExpandProperty name
$who
} catch {
$computer | Out-File $errorlogpath -append
}
Write-Host ""
Write-host "#######################" -ForegroundColor darkGreen
Write-host $computer -ForegroundColor Yellow
Write-host "#######################" -ForegroundColor darkGreen
Invoke-Command $computer -scriptblock {
IF (Test-path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL') {
write-host “SQL is INSTALLED ”
$SQLinst = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
foreach ($SQL in $SQLinst)
{
$p = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$SQL
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Edition
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Version
}
} Else {
write-host “SQL is NOT installed”
}
}
}
}
End{
Write-Output ""
$endtime =Get-Date
$total= $endtime -$starttime
Write-host "Total time for this script to run is $total" -ForegroundColor yellow |ft -AutoSize
Write-Output ""
}