Silently Download and Install SQL Server Management Studio (SSMS)

SSMS is now free and no longer requiring licensing.
It is a separate install and has a more frequent release cycle, usually around 30 days.
To be able to maintain up to date a larger number of SSMS installations I wrote a PowerShell Script for the task.
Of course that a better approach will be to make the download once and then propagate it to other servers, but for now, this works best for me.

<#
.SYNOPSIS
    Silently Download and Install SQL Server Management Studio (SSMS).
.DESCRIPTION
    This script will download and install the latest available SSMS from Microsoft.
.PARAMETER WriteLog
    You want to log to a file. It will generate more than a few files :)
.EXAMPLE
    .\Get-LastSSMS -WriteLog 1
.NOTES
    Author: Viorel Ciucu
    Date: January, 2017
.LINK
 
#>
 
#Requires -RunAsAdministrator
 
[CmdletBinding()]
param (
    [parameter(Mandatory = $false)]
    [int]$WriteLog = 0
)
 
Clear
$ErrorActionPreference="SilentlyContinue"
 
if(-not $PSScriptRoot) {
    $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}
 
$msg = ""
$args = @()
$args += "/install /quiet /norestart" 
 
if($WriteLog -eq 1) { 
    $args += "/log SSMS_$(Get-Date -Format `"yyyyMMdd_HHmm`").txt"
    $msg = "InstallationLog: $PSScriptRoot\SSMS_$(Get-Date -Format `"yyyyMMdd_HHmm`").txt"
}
 
 
Write-Host "Download starting! Please wait.."
 
# Start the download
$Domain = "https://msdn.microsoft.com/en-us/library/mt238290.aspx"
$url = ((Invoke-WebRequest -uri $Domain).Links | Where innerHTML -match "Download SQL Server Management Studio").href | Select -First 1
$job = Start-BitsTransfer -Source $url -DisplayName SSMS -Destination "SSMS-Setup-ENU.exe" -Asynchronous
 
while (($Job.JobState -eq "Transferring") -or ($Job.JobState -eq "Connecting")) { 
    Start-Sleep 5;
} # Poll for status, sleep for 5 seconds, or perform an action.
 
Switch($Job.JobState) {
    "Transferred" { Complete-BitsTransfer -BitsJob $Job; Write-Output "Download completed!" }
    "Error" { $Job | Format-List } # List the errors.
    default { Write-Output "You need to re-run the script, there is a problem with the proxy or Microsoft has changed the download link!"; Exit } # Perform corrective action.
}
 
# We close running SSMS processes
if (Get-Process 'Ssms') {
    Stop-Process -Name Ssms
}
 
Write-Output "Performing silent install..."
 
# Install silently
Start-Process -FilePath SSMS-Setup-ENU.exe -ArgumentList $args -Wait -Verb RunAs
 
Write-Output $msg
Write-Output "All done!"

Hope you’ll find it useful.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close