Created
July 10, 2025 06:43
-
-
Save Digiover/e6a49daf927e68baf0ecb03c3f144b2d to your computer and use it in GitHub Desktop.
Install or update SQL Server Management Studio automatically using this fire-and-forget method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Updates SQL Server Management Studio (SSMS) unattended | |
See: https://www.saotn.org/windows-server/update-sql-server-management-studio-ssms-automatically/ | |
Twitter / X: @Jan_Reilink | |
#> | |
Function Remove-SqlServerManagementStudio { | |
<# | |
Remove any installed SQL Server Management Studio (SSMS) version | |
#> | |
$installedapps = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | |
$installedapps | Where-Object { $_.Displayname -like "Microsoft SQL Server Management Studio*" } | Select-Object DisplayName,VersionMajor | |
$app = $installedapps | Where-Object { $_.Displayname -like "Microsoft SQL Server Management Studio*" } | |
if(!([string]::IsNullOrEmpty($app))) { | |
$executable = $app.UninstallString.Split('"')[1] | |
$arguments = @("/uninstall", "/quiet") | |
if(test-Path "C:\Program Files (x86)\Microsoft SQL Server Management Studio $($app.VersionMajor)\Common7\IDE\Microsoft.AnalysisServices.Deployment.exe") { | |
Remove-Item -Force "C:\Program Files (x86)\Microsoft SQL Server Management Studio $($app.VersionMajor)\Common7\IDE\Microsoft.AnalysisServices.Deployment.exe" | |
} | |
$process = Start-Process -FilePath $executable -ArgumentList $arguments -PassThru | |
$handle = $process.Handle | |
$process.WaitForExit() | |
if($process.ExitCode -ne 0) { | |
Write-Warning "$_ exited with status code $($process.ExitCode)" | |
return $false | |
} else { | |
return $true | |
} | |
} | |
} | |
Function Install-SqlServerManagementStudio { | |
<# | |
Download and install the latest available version at Microsoft | |
#> | |
$ProgressPreference = 'SilentlyContinue' | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
$url = "https://aka.ms/ssmsfullsetup" | |
$result = Invoke-WebRequest -Method GET -Uri $url -Headers $headers -UseBasicParsing | |
$tempFolder = $env:temp | |
$contentDisposition = $result.Headers.'Content-Disposition' | |
$fileName = $contentDisposition.Split('=')[1].Split(';')[0] | |
$path = Join-Path $tempFolder $fileName | |
$file = [System.IO.FileStream]::new($path, [System.IO.FileMode]::Create) | |
$file.write($result.Content, 0, $result.RawContentLength) | |
$file.close() | |
# GC, clean up memory | |
Remove-Variable result | |
$media_path = $file.name | |
$params = @("/Install", "/Quiet") | |
$process = Start-Process -FilePath $media_path -ArgumentList $params -PassThru | |
$handle = $process.Handle | |
$process.WaitForExit() | |
if ($process.ExitCode -ne 0) { | |
Write-Warning "$_ exited with status code $($process.ExitCode)" | |
return $false | |
} else { | |
return $true | |
} | |
} | |
if(Remove-SqlServerManagementStudio) { | |
write-output "Old SQL Server Management Studio version successfully removed." | |
if(Install-SqlServerManagementStudio) { | |
write-output "New SQL Server Management Studio version successfully installed." | |
} else { | |
Write-Output "Oops, installing new version failed." | |
} | |
} else { | |
Write-Output "Oops, removing old version failed." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The fire-and-forget method to update SQL Server Management Studio (SSMS) automatically by uninstalling any installed version and downloading & installing the newest available version from Microsoft.
Blogpost: https://www.saotn.org/windows-server/update-sql-server-management-studio-ssms-automatically/