DBA Scripts: SQL Server Installation and Patching

🔧Part of the DBA-Tools Project, copy/paste SQL Server scripts and health checks.In: Server & Configuration

Ten scripts covering a SQL Server instance’s whole install-to-patch lifecycle: confirm a machine is ready, install unattended, apply sensible defaults, validate the result, keep it patched, and remove it cleanly when it’s done, for both the SQL Server engine and SSMS. Six posts below, each covering a pair of scripts that belong together.


Why This Matters

  • Every script in the set is logged, and most preview safely before doing anything. -WhatIf works without elevation on all of them except install-sql.ps1 and uninstall-sql.ps1, a real, documented inconsistency, not an oversight glossed over.
  • Checks bookend the risky operations. Pre-install and post-install validation exist specifically so an install or a patch isn’t the first time you learn something was misconfigured.
  • Nothing here was tested by actually breaking this site’s own working environment. Install and uninstall of SQL Server or SSMS itself were code-reviewed in full rather than run destructively against the machine every other post on this site depends on, said plainly on the posts where that applies rather than implied by a suspiciously generic “Example Output” section.

Start Here


The Six Posts


How They Fit Together

A sensible order, whether standing up a new server or maintaining an existing one:

1
BEFORE ANYTHING IS INSTALLEDPre-Install CheckConfirm the machine is actually ready, while fixing it is still cheap.
2
THE INSTALL ITSELFInstall and Configure SQL ServerAn unattended install, then the recommended settings applied on top of it.
3
CONFIRM IT, AND KEEP CONFIRMING ITPost-Install ValidationRun it after the build and periodically afterwards, not just once, because configuration drifts.
4
THE MACHINE NEEDS THE TOOLINGInstall SSMSOn any machine that needs management tooling, installed and updated the same scripted way as the engine.
5
ONGOING, NOT JUST AT INSTALL TIMEPatch SQL Server and Check StatusPatch level is a moving target. The builds and lifecycle table is what tells you whether the number you have is current.
6
AT THE END OF ITS LIFEUninstallSQL Server and SSMS both, with a history report confirming what actually happened over the instance lifetime.

Best Practices Across the Series

  • Treat every FAIL from a pre-install check as a blocker, not a note to revisit later.
  • Run post-install validation more than once, configuration drift happens quietly over an instance’s working life.
  • Know which scripts need elevation before scripting a fully unattended pipeline, install-sql.ps1 and uninstall-sql.ps1 require it even for -WhatIf, the rest of the set doesn’t.
  • Never skip the confirmation prompts on uninstall scripts for anything approaching production, -Force-equivalent flags exist for genuinely unattended automation, not as the default habit.
  • Keep CU lookup tables and patch configs current manually and in sync with each other, Microsoft doesn’t expose a queryable source for this.

Frequently Asked Questions

How far behind on patches is too far?

Any gap you cannot explain. Cumulative updates roll up fixes including security ones, so the question is not the number of CUs behind but whether the position was chosen or drifted into. The SQL Server builds reference shows the latest CU for every version, so you always know what current is.

Do I need to restart for a cumulative update?

Yes, plan for the restart rather than hoping. The install itself is usually quick; the outage window is the restart and the recovery of large databases afterwards.

What is worth checking before an install rather than after?

Everything painful to change later: drive layout, service accounts, collation, and tempdb file configuration. Collation in particular is effectively permanent once databases exist.


See Also

This pillar is part of DBA Scripts: The Complete Guide, the map across the whole series organized by the question you’re actually asking.


Summary

Ten scripts, one lifecycle: ready the machine, install, configure, validate, patch, and eventually remove, for both SQL Server and SSMS. What wasn’t safe to test live, actually installing or uninstalling SQL Server or SSMS on this site’s own working machine, is said plainly rather than glossed over.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *