Problem
My previous post talked about how to check the version of SSMS that is installed on different machines remotely.Now we need to find a way to update/upgrade older versions of SSMS remotely based on the list that was generated by our software version checker.
Solution
I created a GUI powershell script and made it executable.
Below is my thought process for making this script:
Step 1
How do I install the SSMS upgrade silently? I ran the executable with /? for help it showed this screen:
I tried the following command to test the SSMS Silent Install:
C:\Temp\SSMS-Setup-ENU-Upgrade.exe /install /quiet /passive /norestart
But there is no option to run it remotely. This needs to run on the machine that I need to upgrade.
Step 2
Copy the installer to the machine that you need to install. The only common place where I can copy the file on the machine is c:\temp directory.
Using powershell, I created a simple script to copy a file from a source path to the server's c:\temp folder:
PS> Copy-Item "<source path>\SSMS-Setup-ENU-Upgrade.exe" -Destination "\\<servername>\C$\temp\SSMS-Setup-ENU-Upgrade.exe" -Force
PS> Copy-Item "<source path>\SSMS-Setup-ENU-Upgrade.exe" -Destination "\\<servername>\C$\temp\SSMS-Setup-ENU-Upgrade.exe" -Force
Step 3
Run the executable remotely. This is where I had spent most of my time troubleshooting. I tried running an Invoke-Command to run SSMS-Setup-ENU-Upgrade.exe with silent install parameters and I got security/permissions error.
As a work around, you can execute a powershell script remotely, and that powershell script can run/call the executable on the server.
Since I know that the executable file will always be in the server's c:\temp folder, I created an update_ssms.ps1 powershell script with the following command:
$ssms_path = "c:\temp\SSMS-Setup-ENU-Upgrade.exe"
$ssms_arguments = "/install /quiet /passive /norestart"
Start-Process -FilePath $ssms_path -ArgumentList $ssms_arguments -NoNewWindow
I used the process of copying the update_ssms.ps1 from a source path to the server's c:\temp folder:
Start-Process -FilePath $ssms_path -ArgumentList $ssms_arguments -NoNewWindow
PS> Copy-Item "<source path>\update_ssms.ps1" -Destination "\\<servername>\C$\temp\update_ssms.ps1" -Force
The following files are now on the server's c:\temp folder:
- SSMS-Setup-ENU-Upgrade.exe
- update_ssms.ps1
Now we can run the update_ssms.ps1 and bypass security/permissions by executing the following command:
PS> Invoke-Command -ComputerName <servername> -ScriptBlock {powershell.exe -ExecutionPolicy ByPass -File c:\temp\update_ssms.ps1}
PS> Invoke-Command -ComputerName <servername> -ScriptBlock {powershell.exe -ExecutionPolicy ByPass -File c:\temp\update_ssms.ps1}
Step 4
Now we can put them all together and be able to upgrade a machine remotely.
But, I still have a few more requirements:
- I want to have the ability to upgrade more than one server in a single run execution.
- I also don't like running the powershell script in a command line and provide several parameters for the script to work.
- I wanted the script to be executable
- The update_ssms.ps1 should be in the same folder as the executable powershell script.
I create a GUI screen for wherein the user will provide the following:
- Name of server or servers. separated by comma (,) if more than one
- Or the path of the server list in .txt file.
- The path of SSMS-Setup-ENU-Upgrade.exe
I used PS2EXE-GUI to compile my powershell script into executable.
The executable file can be downloaded from this URL:
https://gallery.technet.microsoft.com/scriptcenter/Updating-SSMS-v17x-62e5af20
The executable file can be downloaded from this URL:
https://gallery.technet.microsoft.com/scriptcenter/Updating-SSMS-v17x-62e5af20
UPDATE: Technet Gallery has been closed by Microsoft, you can view the archived version on Technet Gallery Archive
Previous post: Installed SSMS Version Checker...