Skip to content

Commit 043d865

Browse files
Steve DanielsonSteve Danielson
authored andcommitted
Code search scripts for Azure DevOps Server 2022
1 parent bc51eea commit 043d865

File tree

115 files changed

+7390
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+7390
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<#
2+
This scripts cleans the shard details table from the configuration database
3+
#>
4+
5+
[CmdletBinding()]
6+
Param(
7+
[Parameter(Mandatory=$True, Position=0, HelpMessage="The Server Instance against which the script is to run.")]
8+
[string]$SQLServerInstance,
9+
10+
[Parameter(Mandatory=$True, Position=1, HelpMessage="Configuration DB")]
11+
[string]$ConfigurationDatabaseName
12+
)
13+
14+
function CleanupShardDetails
15+
{
16+
$SqlFullPath = Join-Path $PWD -ChildPath 'SqlScripts\CleanUpShardDetailsTable.sql'
17+
Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $ConfigurationDatabaseName -Verbose
18+
Write-Host "Cleaned up the shard details..." -ForegroundColor Yellow
19+
}
20+
21+
CleanupShardDetails

Azure_DevOps_Server_2022/Common.psm1

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function ImportSQLModule
2+
{
3+
$moduleCheck = Get-Module -List SQLSERVER
4+
if($moduleCheck)
5+
{
6+
Import-Module -Name SQLSERVER -DisableNameChecking
7+
Write-Host "Loaded SQLSERVER module..." -ForegroundColor Green
8+
}
9+
else
10+
{
11+
Write-Host "Cannot load module SQLSERVER. Trying to load SQLPS module." -ForegroundColor Yellow
12+
13+
$moduleCheck = Get-Module -List SQLPS
14+
15+
if($moduleCheck)
16+
{
17+
Import-Module -Name SQLPS -DisableNameChecking
18+
Write-Host "Loaded SQLPS module..." -ForegroundColor Green
19+
}
20+
else
21+
{
22+
Write-Host "Cannot load SQLPS as well. Try running the script from a machine with SQL Server 2014 or higher installed or powershell 5.0" -ForegroundColor Red
23+
Pop-Location
24+
exit
25+
}
26+
}
27+
}
28+
29+
function ValidateCollectionName
30+
{
31+
[CmdletBinding()]
32+
[OutputType([string])]
33+
Param
34+
(
35+
[string] $SQLServerInstance,
36+
[string] $ConfigurationDatabaseName,
37+
[string] $CollectionName
38+
)
39+
40+
$queryResults = Invoke-Sqlcmd -Query "Select HostID from [dbo].[tbl_ServiceHost] where Name = '$CollectionName' and HostType = 4" -serverInstance $SQLServerInstance -database $ConfigurationDatabaseName -Verbose
41+
42+
$CollectionID = $queryResults | Select-object -ExpandProperty HOSTID
43+
44+
if(!$CollectionID)
45+
{
46+
throw "Invalid Collection Name: '$CollectionName'"
47+
}
48+
49+
return $CollectionID
50+
}
51+
52+
function IsExtensionInstalled
53+
{
54+
[CmdletBinding()]
55+
[OutputType([boolean])]
56+
Param
57+
(
58+
[string] $SQLServerInstance,
59+
[string] $CollectionDatabaseName,
60+
[string] $RegValue
61+
)
62+
63+
return $true
64+
65+
$isCollectionIndexed = Invoke-Sqlcmd -Query "Select RegValue from tbl_RegistryItems where ChildItem like '%$RegValue%' and PartitionId > 0" -ServerInstance $SQLServerInstance -Database $CollectionDatabaseName
66+
67+
if($isCollectionIndexed.RegValue -eq "True")
68+
{
69+
return $true
70+
}
71+
else
72+
{
73+
return $false
74+
}
75+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

Comments
 (0)