forked from microsoft/tigertoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigure_SQLConfig.ps1
More file actions
46 lines (42 loc) · 2.46 KB
/
Configure_SQLConfig.ps1
File metadata and controls
46 lines (42 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# THIS SAMPLE CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
# IF THIS CODE AND INFORMATION IS MODIFIED, THE ENTIRE RISK OF USE OR RESULTS IN
# CONNECTION WITH THE USE OF THIS CODE AND INFORMATION REMAINS WITH THE USER.
# The purpose of this script is
# 1. Configure the SQL Configuration Options - Max Server Memory, MAXDOP, Remote Admin Connection
# 2. Enable/Disable the following on the Model Database
# 2a. AutoShrink, AutoClose, Limit Autogrow
Try
{
Write-Host "************************* SQL Configuration Options *************************"
$TSQLScript1 = "
exec sp_configure 'show advanced options',1;
reconfigure with override"
$TSQLScript2 = "
exec sp_configure 'remote admin connections',1;
reconfigure with override"
$TSQLScript3 = "
exec sp_configure 'max server memory (MB)',5000;
reconfigure with override"
$TSQLScript4 = "
exec sp_configure 'max degree of parallelism',1;
reconfigure with override"
# Execute the T-SQL script against the SQL Server instance
Invoke-SqlCmd -ServerInstance . -Query $TSQLScript1 -Database "master"
Invoke-SqlCmd -ServerInstance . -Query $TSQLScript2 -Database "master"
Invoke-SqlCmd -ServerInstance . -Query $TSQLScript3 -Database "master"
Invoke-SqlCmd -ServerInstance . -Query $TSQLScript4 -Database "master"
Write-Host "************************* Model Database Options *************************"
Invoke-SQLcmd -Query "ALTER DATABASE MODEL SET AUTO_CREATE_STATISTICS ON (INCREMENTAL = ON );" -ServerInstance . -Database "master"
Invoke-SQLcmd -Query "ALTER DATABASE MODEL SET AUTO_UPDATE_STATISTICS ON;" -ServerInstance . -Database "master"
Invoke-SQLcmd -Query "ALTER DATABASE MODEL SET AUTO_UPDATE_STATISTICS_ASYNC OFF;" -ServerInstance . -Database "master"
Invoke-SQLcmd -Query "ALTER DATABASE MODEL SET AUTO_SHRINK OFF;" -ServerInstance . -Database "master"
Invoke-SQLcmd -Query "ALTER DATABASE MODEL SET AUTO_CLOSE OFF;" -ServerInstance . -Database "master"
}
Catch
{
Write-Host "********** Erorr Configuring SQL Config Options ************" -ForegroundColor Red
}