Created
February 9, 2023 05:21
-
-
Save igoravl/44db0d204556bd7ddde7f7e2818fc53f to your computer and use it in GitHub Desktop.
Gets the settings of a Git repository in Azure DevOps Services, using cmdlets from TfsCmdlets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Gets the settings of a Git repository. | |
#> | |
Function Get-TfsGitRepositorySetting { | |
[CmdletBinding()] | |
Param ( | |
# Specifies the name of the setting to retrieve. If not specified, all settings are returned. | |
[Parameter(Position = 0)] | |
[SupportsWildcards()] | |
[string]$Setting = '*', | |
# Specifies the repository to retrieve the settings from. | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[object]$Repository, | |
# Specifies the name of the Team Project, its ID (a GUID), or a Microsoft.TeamFoundation.Core.WebApi.TeamProject object to connect to. When omitted, it defaults to the connection set by Connect-TfsTeamProject (if any). For more details, see the Get-TfsTeamProject cmdlet. | |
[Parameter()] | |
[object]$Project, | |
# Specifies the URL to the Team Project Collection or Azure DevOps Organization to connect to, a TfsTeamProjectCollection object (Windows PowerShell only), or a VssConnection object. You can also connect to an Azure DevOps Services organizations by simply providing its name instead of the full URL. For more details, see the Get-TfsTeamProjectCollection cmdlet. When omitted, it defaults to the connection set by Connect-TfsTeamProjectCollection (if any). | |
[Parameter()] | |
[object]$Collection | |
) | |
Process { | |
# Normalizes the repository object | |
$Repository = Get-TfsGitRepository -Repository $Repository -Project $Project -Collection $Collection | |
# Extracts the repository id and the project name | |
$repoId = $Repository.id | |
$project = $Repository.TeamProject | |
# Gets the repository settings | |
$settings = Invoke-TfsRestApi "$project/_api/_versioncontrol/RepositoryOptions?__v=5&repositoryId=$repoId" | |
# Returns the settings that match the specified setting name | |
$ret = @{} | |
$settings.__wrappedArray ` | |
| Where-Object key -like $Setting ` | |
| ForEach-Object { [PSCustomObject][Ordered]@{ | |
Project = $project | |
Repository = $Repository.Name | |
Setting = $_.key | |
Value = $_.value | |
} } | |
return $ret | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment