Download-SSMS.ps1
<#PSScriptInfo .VERSION 1.1 .GUID 0747e082-3b13-4be0-9149-c1fb73c6dae1 .AUTHOR Karsten.Bott@labbuildr.com .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION This script provides download linkand Version for latest SQL Server Management Studio #> [CmdletBinding()] param ( [ValidateSet('en-us','de-DE','it-IT','fr-FR','ja-JP','es-ES','ko-KR','pt-BR','ru-RU', 'zh-CN','zh-TW')]$lang = 'en-us', [switch]$Download ) $uri = "https://docs.microsoft.com/en-US/sql/ssms/download-sql-server-management-studio-ssms" write-Host "Parsing $uri for SQL Server SSMS Version" $result = Invoke-WebRequest -UseBasicParsing -Uri $Uri if ($result) { Write-Host "Analyzing Content ... " $parse_test = $mytext = $result.Content -replace "<p>" $parse_test_elements = $parse_test -split "</p>" $Release = ($parse_test_elements | Select-String "The release number: ") $Build = ($parse_test_elements | Select-String "The build number for this release: ") [version]$Build = $build -replace "[^0-9.]" [version]$Release = $Release -replace "[^0-9.]" Write-Host -ForegroundColor Magenta "Found Sql Server SSMS Version $($Release.ToString()) build $($Build.ToString()) " $redirector = $result.Links | where { $_.outerHTML -Match "Download SQL Server Management Studio" -and $_.outerHTML -NotMatch "Upgrade"} Write-Host "Parsing redirector link $($redirector.href)" Switch ($lang) { 'de-DE' { $clcid ='0x407' } 'en-US' { $clcid = '0x409' } 'it-IT' { $clcid = '0x410' } 'ja-JP' { $clcid = '0x411' } 'ko-KR' { $clcid = '0x412' } 'pt-BR' { $clcid = '0x416' } 'ru-RU' { $clcid = '0x419' } 'es-ES' { $clcid = '0x40a' } 'fr-FR' { $clcid = '0x40c' } 'zh-CN' { $clcid = '0x804' } 'zh-TW' { $clcid = '0x404' } } $country_redirector = "$($redirector.href)&clcid=$($clcid)" $Download_URI = Invoke-WebRequest $country_redirector -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue Write-Host "Found download Link $($Download_URI.Headers.Location)" if ($download.ispresent) { Start-BitsTransfer -Description "Downloading Sql Server SSMS Version $($Release.ToString()) build $($Build.ToString()) " -Destination "$HOME/Downloads" -Source $($Download_URI.Headers.Location) } $object = New-Object psobject $object | Add-Member -MemberType NoteProperty -Name Release -Value $Release $object | Add-Member -MemberType NoteProperty -Name Build -Value $Build $object | Add-Member -MemberType NoteProperty -Name URI -Value $($Download_URI.Headers.Location) Write-Output $object } else { Write-Error "Error Parsing $uri" } |