Applying cumulative updates to SQL Servers remotely using PowerShell.

I had to apply some cumulative updates to a couple of SQL Servers and was struggling to remote desktop onto the server.

So instead of continuing  with struggling to connect I decided to try and use a Powershell remote session which turned out to work quite well.

  • Copy the cumulative update to the server to be patched.
  • Open an elevated Powershell command prompt.
  • Enter-PSSession -ComputerName <COMPUTERNAME>
  • cd to the folder with the CU
  • Run the command to install the cumulative update.
  • Open the installer logs to confirm the installation succeeded (Log File Location).

As this is a Powershell remote session we want to run the installer with no GUI, so here is the command to update all instances.

.\SQLServer2012-KB3007556-x64.exe  /q /action=patch /allinstances /IAcceptSQLServerLicenseTerms

 
PSRemotePatch

 


Comments

+2 #4 Paul 2017-04-23 08:24
Quoting SURESH R:
This is really cool one. Is there a way to pass the computername as a parameter from a text file and loop these commands through it so that we can patch multiple server instances

It's probably not possible using enter-pssession , but invoke-command, with the -asjob switch would probably work. I'll have a think further about it.
+1 #3 SURESH R 2017-04-22 03:21
This is really cool one. Is there a way to pass the computername as a parameter from a text file and loop these commands through it so that we can patch multiple server instances
+4 #2 Paul 2016-03-06 10:18
Quoting Sudhir Giri:
Great article! Short, precise and clear.
Is it possible that we can have the setup file at one location and apply patches on remote servers?

I'm sure it will be possible to save the update file in a central location and access it via a UNC path.
Even if it doesn't run from the UNC path you could copy the file locally in your Powershell script.
-1 #1 Sudhir Giri 2015-08-04 12:34
Great article! Short, precise and clear.
Is it possible that we can have the setup file at one location and apply patches on remote servers?

Comments are now closed for this entry

MCM 2013rgb 1262

MCSM 2013rgb 1546