1
+ [CmdletBinding ()]
2
+ Param (
3
+ [Parameter (Mandatory = $True , Position = 0 , HelpMessage = " The Server Instance against which the script is to run." )]
4
+ [string ]$SQLServerInstance ,
5
+
6
+ [Parameter (Mandatory = $True , Position = 1 , HelpMessage = " Configuration DB" )]
7
+ [string ]$ConfigurationDatabaseName ,
8
+
9
+ [Parameter (Mandatory = $False , Position = 2 , HelpMessage = " Pause Indexing for Code, WorkItem or All." )]
10
+ [string ]$EntityType = " All"
11
+ )
12
+
13
+ function ImportSQLModule
14
+ {
15
+ $moduleCheck = Get-Module - List SQLPS
16
+ if ($moduleCheck )
17
+ {
18
+ Import-Module - Name SQLPS - DisableNameChecking
19
+ Write-Host " Loaded SQLPS module..." - ForegroundColor Green
20
+ }
21
+ else
22
+ {
23
+ Write-Error " Cannot load module SQLPS. Please try from a machine running SQL Server 2012 or higher."
24
+ Pop-Location
25
+ exit
26
+ }
27
+ }
28
+
29
+ function PauseCodeIndexing
30
+ {
31
+ $SqlFullPath = Join-Path $PWD - ChildPath ' SqlScripts\PauseCodeIndexing.sql'
32
+ Invoke-Sqlcmd - InputFile $SqlFullPath - serverInstance $SQLServerInstance - database $ConfigurationDatabaseName
33
+ }
34
+
35
+ function PauseWorkItemIndexing
36
+ {
37
+ $SqlFullPath = Join-Path $PWD - ChildPath ' SqlScripts\PauseWorkItemIndexing.sql'
38
+ Invoke-Sqlcmd - InputFile $SqlFullPath - serverInstance $SQLServerInstance - database $ConfigurationDatabaseName
39
+ }
40
+
41
+ Write-Host " This would pause indexing for all the collections. Do you want to continue - Yes or No? " - NoNewline - ForegroundColor Magenta
42
+ $userInput = Read-Host
43
+
44
+ if ($userInput -like " Yes" )
45
+ {
46
+ [System.ENVIRONMENT ]::CurrentDirectory = $PWD
47
+ Push-Location
48
+ ImportSQLModule
49
+
50
+ switch ($EntityType )
51
+ {
52
+ " All"
53
+ {
54
+ Write-Host " Pausing indexing for Code and WorkItem..." - ForegroundColor Green
55
+ PauseCodeIndexing
56
+ PauseWorkItemIndexing
57
+ Write-Host " Code and WorkItem Indexing has been paused!! Run ResumeIndexing.ps1 to resume indexing." - ForegroundColor Green
58
+ }
59
+ " WorkItem"
60
+ {
61
+ Write-Host " Pausing indexing for WorkItem..." - ForegroundColor Green
62
+ PauseWorkItemIndexing
63
+ Write-Host " WorkItem Indexing has been paused!! Run ResumeIndexing.ps1 to resume indexing." - ForegroundColor Green
64
+ }
65
+ " Code"
66
+ {
67
+ Write-Host " Pausing indexing for Code..." - ForegroundColor Green
68
+ PauseCodeIndexing
69
+ Write-Host " Code Indexing has been paused!! Run ResumeIndexing.ps1 to resume indexing." - ForegroundColor Green
70
+ }
71
+ default
72
+ {
73
+ Write-Host " Enter a valid EntityType i.e. Code or WorkItem or All" - ForegroundColor Red
74
+ }
75
+ }
76
+
77
+ Pop-Location
78
+ }
79
+ else
80
+ {
81
+ Write-Warning " Exiting! Indexing was not paused." - ForegroundColor Cyan
82
+ }
0 commit comments