|
| 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="Collection Database name.")] |
| 7 | + [string]$CollectionDatabaseName, |
| 8 | + |
| 9 | + [Parameter(Mandatory=$True, Position=2, HelpMessage="Configuration DB")] |
| 10 | + [string]$ConfigurationDatabaseName, |
| 11 | + |
| 12 | + [Parameter(Mandatory=$True, Position=3, HelpMessage="Enter the Collection Name here.")] |
| 13 | + [string]$CollectionName, |
| 14 | + |
| 15 | + [Parameter(Mandatory=$True, Position=4, HelpMessage="Enter operation type 'Add' for adding more folder(s), 'Remove' for removing folder(s) from exclusion list, 'Delete' for deleting all the folders in the list, 'Fetch' for fetching list of folders present in exclusion list.")] |
| 16 | + [string]$OperationType |
| 17 | +) |
| 18 | + |
| 19 | +Import-Module .\Common.psm1 -Force |
| 20 | + |
| 21 | +function AddExcludedFolders |
| 22 | +{ |
| 23 | + $foldersList = Read-Host 'Specify comma separated list of folders to Exclude from Indexing' |
| 24 | + $Params = "CollectionId='$CollectionID'", "FolderPaths='$foldersList'" |
| 25 | + $SqlFullPath = Join-Path $PWD -ChildPath 'SqlScripts\TfvcExcludedFolders\AddFoldersInExclusionList.sql' |
| 26 | + Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $Params |
| 27 | + Write-Host "Added Given folders to Indexing Exclusion list" -ForegroundColor Yellow |
| 28 | +} |
| 29 | + |
| 30 | +function FetchExcludedFoldersList |
| 31 | +{ |
| 32 | + $Params = "CollectionId='$CollectionID'" |
| 33 | + $SqlFullPath = Join-Path $PWD -ChildPath 'SqlScripts\TfvcExcludedFolders\FetchFoldersInExclusionList.sql' |
| 34 | + $QueryResults = Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $Params |
| 35 | + |
| 36 | + $ExcludedFoldersList = $QueryResults | Select-object -ExpandProperty ExcludedFolders |
| 37 | + Write-Host "Folders present in Indexing Exclusion list are: '$ExcludedFoldersList'" -ForegroundColor Yellow |
| 38 | +} |
| 39 | + |
| 40 | +function RemoveFoldersFromExclusionList |
| 41 | +{ |
| 42 | + $foldersList = Read-Host 'Specify comma separated list of folders to remove from Indexing Exclusion list' |
| 43 | + $Params = "CollectionId='$CollectionID'", "FolderPaths='$foldersList'" |
| 44 | + $SqlFullPath = Join-Path $PWD -ChildPath 'SqlScripts\TfvcExcludedFolders\RemoveFoldersFromExclusionList.sql' |
| 45 | + Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $Params |
| 46 | + Write-Host "Removed given folders from Indexing Exclusion list" -ForegroundColor Yellow |
| 47 | +} |
| 48 | + |
| 49 | +function DeleteAllExcludedFolders |
| 50 | +{ |
| 51 | + $Params = "CollectionId='$CollectionID'" |
| 52 | + $SqlFullPath = Join-Path $PWD -ChildPath 'SqlScripts\TfvcExcludedFolders\DeleteAllFoldersInExclusionList.sql' |
| 53 | + Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $Params |
| 54 | + Write-Host "Deleted all folders from Indexing Exclusion list" -ForegroundColor Yellow |
| 55 | +} |
| 56 | + |
| 57 | +[System.ENVIRONMENT]::CurrentDirectory = $PWD |
| 58 | +Push-Location |
| 59 | +ImportSQLModule |
| 60 | + |
| 61 | +$CollectionID = ValidateCollectionName $SQLServerInstance $ConfigurationDatabaseName $CollectionName |
| 62 | + |
| 63 | +switch ($OperationType) |
| 64 | +{ |
| 65 | + "Add" |
| 66 | + { |
| 67 | + Write-Host "Adding folders to exclusion list..." -ForegroundColor Green |
| 68 | + AddExcludedFolders |
| 69 | + } |
| 70 | + "Fetch" |
| 71 | + { |
| 72 | + Write-Host "Fetching folders present in exclusion list..." -ForegroundColor Green |
| 73 | + FetchExcludedFoldersList |
| 74 | + } |
| 75 | + "Remove" |
| 76 | + { |
| 77 | + Write-Host "Removing given folders from exclusion list..." -ForegroundColor Green |
| 78 | + RemoveFoldersFromExclusionList |
| 79 | + } |
| 80 | + "Delete" |
| 81 | + { |
| 82 | + Write-Host "Deleting all the folders from exclusion list..." -ForegroundColor Green |
| 83 | + DeleteAllExcludedFolders |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +Pop-Location |
0 commit comments