CheckClientUpdates.ps1 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Helper functions to check if TLS 1.2 updates are required
  2. # Script currently supports checking for the following:
  3. # a. Check if SQL Server Native Client can support TLS 1.2
  4. # b. Check if Microsoft ODBC Driver for SQL Server can support TLS 1.2
  5. # This script is restricted to work on x64 and x86 platforms
  6. <#
  7. Fix list:
  8. v1.1:
  9. Edit to use Win32Reg_AddRemovePrograms based on Issue reported by codykonior (Issue #20)
  10. v1.2:
  11. Fixes to use Windows Registry as suggested by modsqlguy as an alternative (Issue #22)
  12. Fixes to account for 10.51.x version numbers for SQL Server 2008 R2 as reported by modsqlguy (Issue #23)
  13. #>
  14. Function Check-Sqlncli
  15. {
  16. # Fetch the different Native Client installations found on the machine
  17. $sqlncli = Get-InstalledPrograms | Where-Object {$_.DisplayName -like "*Native Client*" -and $_.Publisher -like "*Microsoft*"} | Select DisplayName,DisplayVersion
  18. # Check and report if an update is required for each entry found
  19. foreach ($cli in $sqlncli)
  20. {
  21. # SQL Server 2012 and 2014
  22. if ($cli.DisplayVersion.Split(".")[2] -lt 6538 -and $cli.DisplayVersion.Split(".")[0] -eq 11)
  23. {
  24. Write-Host $cli.DisplayName "with version" $cli.DisplayVersion " needs to be updated to use TLS 1.2" -ForegroundColor Red
  25. }
  26. # SQL Server 2008
  27. elseif ($cli.DisplayVersion.Split(".")[2] -lt 6543 -and $cli.DisplayVersion.Split(".")[1] -eq 0 -and $cli.DisplayVersion.Split(".")[0] -eq 10)
  28. {
  29. Write-Host $cli.DisplayName "with version" $cli.DisplayVersion " needs to be updated to use TLS 1.2" -ForegroundColor Red
  30. }
  31. # SQL Server 2008 R2
  32. elseif ($cli.DisplayVersion.Split(".")[2] -lt 6537 -and ($cli.DisplayVersion.Split(".")[1] -eq 50 -or $cli.DisplayVersion.Split(".")[1] -eq 51) -and $cli.DisplayVersion.Split(".")[0] -eq 10)
  33. {
  34. Write-Host $cli.DisplayName "with version" $cli.DisplayVersion " needs to be updated to use TLS 1.2" -ForegroundColor Red
  35. }
  36. else
  37. {
  38. Write-Host $cli.DisplayName "with version" $cli.DisplayVersion " supports TLS 1.2" -ForegroundColor Green
  39. }
  40. }
  41. }
  42. Function Check-SqlODBC($server)
  43. {
  44. # Fetch the different MS SQL ODBC installations found on the machine
  45. #$sqlodbc = Get-WmiObject -Class Win32reg_AddRemovePrograms | Where-Object {$_.DisplayName -like "*ODBC*" -and $_.Publisher -like "*Microsoft*"} | Select DisplayName,Version
  46. $sqlodbc = Get-InstalledPrograms | Where-Object {$_.DisplayName -like "*ODBC*" -and $_.Publisher -like "*Microsoft*"} | Select DisplayName,DisplayVersion
  47. # Check and report if an update is required for each entry found
  48. foreach ($cli in $sqlodbc)
  49. {
  50. # SQL Server 2012 and 2014
  51. if ($cli.DisplayVersion.Split(".")[2] -lt 4219 -and $cli.DisplayVersion.Split(".")[0] -eq 12)
  52. {
  53. Write-Host $cli.DisplayName "with version" $cli.DisplayVersion " needs to be updated to use TLS 1.2" -ForegroundColor Red
  54. }
  55. else
  56. {
  57. Write-Host $cli.DisplayName "with version" $cli.DisplayVersion " supports TLS 1.2" -ForegroundColor Green
  58. }
  59. }
  60. }
  61. <#
  62. Get-InstalledPrograms code snippet is from https://blogs.technet.microsoft.com/heyscriptingguy/2011/11/13/use-powershell-to-quickly-find-installed-software/
  63. #>
  64. Function Get-InstalledPrograms()
  65. {
  66. $array = @()
  67. #Define the variable to hold the location of Currently Installed Programs
  68.     $UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" 
  69.     #Create an instance of the Registry Object and open the HKLM base key
  70.     $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME) 
  71.     #Drill down into the Uninstall key using the OpenSubKey Method
  72.     $regkey=$reg.OpenSubKey($UninstallKey) 
  73.     #Retrieve an array of string that contain all the subkey names
  74.     $subkeys=$regkey.GetSubKeyNames()
  75.     #Open each Subkey and use GetValue Method to return the required values for each
  76.     foreach ($key in $subkeys)
  77. {
  78.         $thisKey=$UninstallKey+"\\"+$key 
  79.         $thisSubKey=$reg.OpenSubKey($thisKey) 
  80.         $obj = New-Object PSObject
  81.         $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $env:COMPUTERNAME
  82.         $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
  83.         $obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
  84.         $obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
  85.         $obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
  86.         $array += $obj
  87.     } 
  88. return $array
  89. }
  90. # Call the functions
  91. Check-Sqlncli $env:COMPUTERNAME
  92. Check-SqlODBC $env:COMPUTERNAME