How to add startup parameters for all the SQL Server instances (PowerShell)

Introduction

This PowerShell script show how to add startup parameters for all the SQL Server instances.  

Scenarios

Some people ask how to add startup parameters to a batch of SQL Server instances. If we add the parameters one by one for all the instances on a SQL Server, it will cost a lot of time. This script will help you achieve your goal in a convenient way. If the startup parameters already exist on the server, the script will skip the ones. 

Script

You can use this script in this way: 
1. Run Microsoft PowerShell as Administrator

2. Run the script in the form: Path
For example:
D:\SyncupAddParamters.ps1

3. Press “Enter” and enter the parameters
Note: the delimiter should be comma ”,”.

4. After the script finishes running, we’ll get the following figure:

 

Here are some code snippets for your references.

 

PowerShell
Edit|Remove
param( 
    # The parameter you want to add 
    [Parameter(Mandatory = $true)][String]$StartupParameters 
) 
 
# get all the instances on a server$property = Get-ItemProperty"HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"$instancesObject = $property.psobject.properties | ?{$_.Value -like 'MSSQL*'}  
$instances = $instancesObject.Value 

 

Prerequisites

SQL Server 2008/SQL Server 2008 R2 /SQL Server 2012