Configure_SQLConfig.ps1 2.5 KB

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