Powershell script for unattended install of SQL Server standard patches

23 July,2019 by Jack Vamvas

Question: Do you have a powershell script allowing me to dynamically create a drive - pointing to a network share , and then start an unattended install of SQL Server patching? I'll afdapt the script to drop onto a server and execute according to schedule .

Answer: Here is an example of  powershell script that applies SQL Server 2016 SP2 CU7 , although you can apply the same framework for other patching .

Some key points to note:

1) Replace "my_path" with the network path . The drive is added by use of the PS-Drive cmdlet. If you want to read more on creating a drive through Powershell read Powershell assign a drive and mount point 

This step creates a PS-Drive , which can then be accessed by later stages of the script

2)Replace "myPatch" , with the actual SQL Server patch file - which should be located on the drive you referenced above.  This uses the Start-Process cmdlet .

 

 

@echo off
echo	Unattended install of SQL Server 2016  Standard patches
 
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe New-PSDrive -Name "S" -Root '"\\my_path\"' -Persist -PSProvider "FileSystem"

pause 

echo %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe Start-Process -FilePath "S:\myPatch.exe" -ArgumentList "/quiet" -Wait
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe Start-Process -FilePath "S:\myPatch.exe" -ArgumentList "/allinstances " -Wait

pause



:syntax
echo setup_SQL_Server_2016_patches
echo setup_SQL_Server_2016_patches [InstanceName] 

:end


Read more on powerhsell scripts

Powershell Scripts

Backup a SQL database to a remote drive

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Powershell script for unattended install of SQL Server standard patches


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer