DevOpsHandling/Get-RepositoryId.ps1
function Get-RepositoryId { Param ( [Parameter(Mandatory=$true)] [string]$devOpsOrganization, [Parameter(Mandatory=$true)] [string]$devOpsProjectName, [Parameter(Mandatory=$false)] [string]$repositoryName, [Parameter(Mandatory=$true)] [string]$devOpsToken ) $repos = (Invoke-AzureDevOpsApi -url ('https://dev.azure.com/{0}/{1}/_apis/git/repositories' -f $devOpsOrganization, $devOpsProjectName) -devOpsToken $devOpsToken) try { if ($repositoryName -ne '') { $id = ($repos.value | Where-Object name -like ('*{0}*' -f $repositoryName)).id } else { $id = $repos.value.item(0).id } if ($id -eq '' -or $null -eq $id) { $id = Get-RepositoryId -devOpsOrganization $devOpsOrganization -devOpsProjectName $devOpsProjectName -repositoryName '' -devOpsToken $devOpsToken } } catch { throw "Could not find repository id for $repositoryName" } return $id } Export-ModuleMember Get-RepositoryId |