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
Comments
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.
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.
Is it possible that we can have the setup file at one location and apply patches on remote servers?