functions/Get-AzureDevOpsItemContent.ps1
|
function Get-AzureDevOpsItemContent { param( [Parameter(Mandatory)] [string]$Project, [Parameter(Mandatory)] [string]$Repository, [Parameter(Mandatory)] [string]$Path ) $returnContent = $null #Load helpers $helpersDirPath = Join-Path -Path $PSScriptRoot -ChildPath '..\helpers' . (Join-Path -Path $helpersDirPath -ChildPath 'testAzureDevOpsConnection.ps1') testAzureDevOpsConnection $Project = $Project.ToLower().Trim() $Repository = $Repository.ToLower().Trim() $Path = $Path.ToLower().Trim() $incContent = $IncludeContent.IsPresent $uri = '{0}/{1}/_apis/git/repositories/{2}/items?path={3}&includeContent=true&api-version=7.1' $uri = ($uri -f $script:AzureDevOpsOrgUrl, $Project, $Repository, $Path, $RecursionLevel, $incContent) $method = 'GET' $headers = @{ "Authorization" = $script:AzureDevOpsAuthHeaderValue "Content-Type" = "application/json" } $response = $null try { $response = Invoke-WebRequest -Uri $uri -Method $method -Headers $headers -UseBasicParsing } catch { $response = $null } if (($response -ne $null) -and ($response.StatusCode -eq 200)) { $returnContent = [System.Text.Encoding]::UTF8.GetString($response.content) } return $returnContent; } |