diff --git a/Azure_DevOps_Server_2019/GitMultiBranchConfigureForCodeSearch.ps1 b/Azure_DevOps_Server_2019/GitMultiBranchConfigureForCodeSearch.ps1 new file mode 100644 index 0000000..d1845a1 --- /dev/null +++ b/Azure_DevOps_Server_2019/GitMultiBranchConfigureForCodeSearch.ps1 @@ -0,0 +1,27 @@ +[CmdletBinding()] +Param( + [Parameter(Mandatory=$True, Position=0, HelpMessage="The Server Instance against which the script is to run.")] + [string]$SQLServerInstance, + + [Parameter(Mandatory=$True, Position=2, HelpMessage="Collection DB")] + [string]$CollectionDatabaseName, + + [Parameter(Mandatory=$True, Position=2, HelpMessage="Configuration DB")] + [string]$ConfigurationDatabaseName, + + [Parameter(Mandatory=$True, Position=3, HelpMessage="Enter the Collection Name here.")] + [string]$CollectionName, + + [Parameter(Mandatory=$True, Position=3, HelpMessage="Enter number of branches that you want to configure for Code Search for Git repositories.")] + [string]$NumberOfBranches +) + +ImportSQLModule + +$CollectionID = ValidateCollectionName $SQLServerInstance $ConfigurationDatabaseName $CollectionName + +$Params = "CollectionId='$CollectionID'", "BranchCountToConfigure='$NumberOfBranches'" +$SqlFullPath = Join-Path $PSScriptRoot -ChildPath 'SqlScripts\GitMultiBranchConfigChange.sql' +Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $Params +Write-Host "Changed the number of branches configured to '$NumberOfBranches'." -NoNewLine +Write-Host " Note that it may take upto 12 hours for Search to start indexing the newly configured branches after those are configured via settings page." -ForegroundColor Green diff --git a/Azure_DevOps_Server_2019/SqlScripts/GitMultiBranchConfigChange.sql b/Azure_DevOps_Server_2019/SqlScripts/GitMultiBranchConfigChange.sql new file mode 100644 index 0000000..89be626 --- /dev/null +++ b/Azure_DevOps_Server_2019/SqlScripts/GitMultiBranchConfigChange.sql @@ -0,0 +1,15 @@ +/* +This script sets the number of branches that can be configured for code search for Git repositories. +This has to be run against COLLECTION DB. +*/ + +Declare @CollectionId uniqueidentifier = $(CollectionID); +Declare @BranchCount int = $(BranchCountToConfigure); + +-- Step1 – Change the reg setting that governs number of Git branches that can configured for code search. +DECLARE @partitionID VARCHAR(50) +SELECT @partitionID = PartitionID FROM [dbo].[tbl_DatabasePartitionMap] WHERE ServiceHostId = @CollectionId + +DECLARE @features [dbo].[typ_KeyValuePairStringTableNullable] +INSERT INTO @features values('#\Service\Search\Settings\MaxNumberOfConfigurableBranchesForSearch\', @BranchCount) +EXEC prc_UpdateRegistry @partitionId = @partitionID, @identityName = '00000000-0000-0000-0000-000000000000', @registryUpdates = @features diff --git a/Azure_DevOps_Server_2019/TfvcDestroy_DeleteFilesFromES.ps1 b/Azure_DevOps_Server_2019/TfvcDestroy_DeleteFilesFromES.ps1 new file mode 100644 index 0000000..e6db3c3 --- /dev/null +++ b/Azure_DevOps_Server_2019/TfvcDestroy_DeleteFilesFromES.ps1 @@ -0,0 +1,57 @@ +[CmdletBinding()] +Param +( + [Parameter(Mandatory=$True)] + [string] $SQLServerInstance, + + [Parameter(Mandatory=$True)] + [string] $ConfigurationDatabaseName, + + [Parameter(Mandatory=$True)] + [string] $CollectionName, + + [Parameter(Mandatory=$True)] + [uri] $ElasticsearchServiceUrl, + + [Parameter(Mandatory=$True)] + [PSCredential] $ElasticsearchServiceCredential, + + [Parameter(Mandatory=$True)] + [string] $FileOrFolderPath +) + +if(!$FileOrFolderPath.StartsWith("$/")) +{ + throw "Please provide proper Tfvc file/folder path that starts with $/" +} + +$CollectionId = Invoke-Sqlcmd -Query "Select HostID from dbo.tbl_ServiceHost WHERE Name = '$CollectionName' AND HostType = 4" -ServerInstance $SQLServerInstance -Database $ConfigurationDatabaseName | Select-Object -ExpandProperty HostId +if (!$CollectionId) +{ + throw "Collection with name [$CollectionName] not found." +} + +$WildChar = "*"; +$body = @" +{ + "query": { + "bool": { + "must": [ { + "term": { + "collectionId": { + "value": "$CollectionId" + }}},{ + "wildcard": { + "filePathOriginal": { + "value": "$FileOrFolderPath$WildChar" + } + }}] + }} +} +"@ + + +Write-Host "Attempting delete for all files under path (honouring case sensitivity): $FileOrFolderPath" +$Command = "code*/_delete_by_query" +$ESDeleteResponse = Invoke-WebRequest -Method POST -Uri $ElasticsearchServiceUrl$Command -Body $Body -Credential $ElasticsearchServiceCredential -ContentType "application/json" +Write-Host "Delete operation response: $ESDeleteResponse" \ No newline at end of file diff --git a/TFS_2018Update2/TfvcDestroy_DeleteFilesFromES.ps1 b/TFS_2018Update2/TfvcDestroy_DeleteFilesFromES.ps1 new file mode 100644 index 0000000..54e86d9 --- /dev/null +++ b/TFS_2018Update2/TfvcDestroy_DeleteFilesFromES.ps1 @@ -0,0 +1,54 @@ +[CmdletBinding()] +Param +( + [Parameter(Mandatory=$True)] + [string] $SQLServerInstance, + + [Parameter(Mandatory=$True)] + [string] $ConfigurationDatabaseName, + + [Parameter(Mandatory=$True)] + [string] $CollectionName, + + [Parameter(Mandatory=$True)] + [uri] $ElasticsearchServiceUrl, + + [Parameter(Mandatory=$True)] + [string] $FileOrFolderPath +) + +if(!$FileOrFolderPath.StartsWith("$/")) +{ + throw "Please provide proper Tfvc file/folder path that starts with $/" +} + +$CollectionId = Invoke-Sqlcmd -Query "Select HostID from dbo.tbl_ServiceHost WHERE Name = '$CollectionName' AND HostType = 4" -ServerInstance $SQLServerInstance -Database $ConfigurationDatabaseName | Select-Object -ExpandProperty HostId +if (!$CollectionId) +{ + throw "Collection with name [$CollectionName] not found." +} + +$WildChar = "*"; +$body = @" +{ + "query": { + "bool": { + "must": [ { + "term": { + "collectionId": { + "value": "$CollectionId" + }}},{ + "wildcard": { + "filePathOriginal": { + "value": "$FileOrFolderPath$WildChar" + } + }}] + }} +} +"@ + + +Write-Host "Attempting delete for all files under path (honouring case sensitivity): $FileOrFolderPath" +$Command = "code*/_delete_by_query" +$ESDeleteResponse = Invoke-WebRequest -Method POST -Uri $ElasticsearchServiceUrl$Command -Body $Body -ContentType "application/json" +Write-Host "Delete operation response: $ESDeleteResponse" \ No newline at end of file diff --git a/TFS_2018Update3/GitMultiBranchConfigureForCodeSearch.ps1 b/TFS_2018Update3/GitMultiBranchConfigureForCodeSearch.ps1 new file mode 100644 index 0000000..d1845a1 --- /dev/null +++ b/TFS_2018Update3/GitMultiBranchConfigureForCodeSearch.ps1 @@ -0,0 +1,27 @@ +[CmdletBinding()] +Param( + [Parameter(Mandatory=$True, Position=0, HelpMessage="The Server Instance against which the script is to run.")] + [string]$SQLServerInstance, + + [Parameter(Mandatory=$True, Position=2, HelpMessage="Collection DB")] + [string]$CollectionDatabaseName, + + [Parameter(Mandatory=$True, Position=2, HelpMessage="Configuration DB")] + [string]$ConfigurationDatabaseName, + + [Parameter(Mandatory=$True, Position=3, HelpMessage="Enter the Collection Name here.")] + [string]$CollectionName, + + [Parameter(Mandatory=$True, Position=3, HelpMessage="Enter number of branches that you want to configure for Code Search for Git repositories.")] + [string]$NumberOfBranches +) + +ImportSQLModule + +$CollectionID = ValidateCollectionName $SQLServerInstance $ConfigurationDatabaseName $CollectionName + +$Params = "CollectionId='$CollectionID'", "BranchCountToConfigure='$NumberOfBranches'" +$SqlFullPath = Join-Path $PSScriptRoot -ChildPath 'SqlScripts\GitMultiBranchConfigChange.sql' +Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $Params +Write-Host "Changed the number of branches configured to '$NumberOfBranches'." -NoNewLine +Write-Host " Note that it may take upto 12 hours for Search to start indexing the newly configured branches after those are configured via settings page." -ForegroundColor Green diff --git a/TFS_2018Update3/SqlScripts/GitMultiBranchConfigChange.sql b/TFS_2018Update3/SqlScripts/GitMultiBranchConfigChange.sql new file mode 100644 index 0000000..89be626 --- /dev/null +++ b/TFS_2018Update3/SqlScripts/GitMultiBranchConfigChange.sql @@ -0,0 +1,15 @@ +/* +This script sets the number of branches that can be configured for code search for Git repositories. +This has to be run against COLLECTION DB. +*/ + +Declare @CollectionId uniqueidentifier = $(CollectionID); +Declare @BranchCount int = $(BranchCountToConfigure); + +-- Step1 – Change the reg setting that governs number of Git branches that can configured for code search. +DECLARE @partitionID VARCHAR(50) +SELECT @partitionID = PartitionID FROM [dbo].[tbl_DatabasePartitionMap] WHERE ServiceHostId = @CollectionId + +DECLARE @features [dbo].[typ_KeyValuePairStringTableNullable] +INSERT INTO @features values('#\Service\Search\Settings\MaxNumberOfConfigurableBranchesForSearch\', @BranchCount) +EXEC prc_UpdateRegistry @partitionId = @partitionID, @identityName = '00000000-0000-0000-0000-000000000000', @registryUpdates = @features diff --git a/TFS_2018Update3/TfvcDestroy_DeleteFilesFromES.ps1 b/TFS_2018Update3/TfvcDestroy_DeleteFilesFromES.ps1 new file mode 100644 index 0000000..e6db3c3 --- /dev/null +++ b/TFS_2018Update3/TfvcDestroy_DeleteFilesFromES.ps1 @@ -0,0 +1,57 @@ +[CmdletBinding()] +Param +( + [Parameter(Mandatory=$True)] + [string] $SQLServerInstance, + + [Parameter(Mandatory=$True)] + [string] $ConfigurationDatabaseName, + + [Parameter(Mandatory=$True)] + [string] $CollectionName, + + [Parameter(Mandatory=$True)] + [uri] $ElasticsearchServiceUrl, + + [Parameter(Mandatory=$True)] + [PSCredential] $ElasticsearchServiceCredential, + + [Parameter(Mandatory=$True)] + [string] $FileOrFolderPath +) + +if(!$FileOrFolderPath.StartsWith("$/")) +{ + throw "Please provide proper Tfvc file/folder path that starts with $/" +} + +$CollectionId = Invoke-Sqlcmd -Query "Select HostID from dbo.tbl_ServiceHost WHERE Name = '$CollectionName' AND HostType = 4" -ServerInstance $SQLServerInstance -Database $ConfigurationDatabaseName | Select-Object -ExpandProperty HostId +if (!$CollectionId) +{ + throw "Collection with name [$CollectionName] not found." +} + +$WildChar = "*"; +$body = @" +{ + "query": { + "bool": { + "must": [ { + "term": { + "collectionId": { + "value": "$CollectionId" + }}},{ + "wildcard": { + "filePathOriginal": { + "value": "$FileOrFolderPath$WildChar" + } + }}] + }} +} +"@ + + +Write-Host "Attempting delete for all files under path (honouring case sensitivity): $FileOrFolderPath" +$Command = "code*/_delete_by_query" +$ESDeleteResponse = Invoke-WebRequest -Method POST -Uri $ElasticsearchServiceUrl$Command -Body $Body -Credential $ElasticsearchServiceCredential -ContentType "application/json" +Write-Host "Delete operation response: $ESDeleteResponse" \ No newline at end of file