TeamFoundation/Public/Build/Get-TfsBuildDefinition.ps1
function Get-TfsBuildDefinition { [CmdletBinding(DefaultParameterSetName = 'Cred')] param ( [Parameter(Mandatory)] [string] $InstanceName, [Parameter(Mandatory)] [string] $CollectionName, [ValidateRange(1, 65535)] [uint32] $Port, [string] $ApiVersion = '2.0', [Parameter(Mandatory)] [string] $ProjectName, [Parameter(Mandatory)] [string] $DefinitionName, [string] $QueueName, [switch] $UseSsl, [Parameter(Mandatory, ParameterSetName = 'Cred')] [pscredential] $Credential, [Parameter(Mandatory, ParameterSetName = 'Pat')] [string] $PersonalAccessToken ) $requestUrl = if ($UseSsl) {'https://' } else {'http://'} $requestUrl += if ( $Port -gt 0) { '{0}{1}/{2}/{3}/_apis/build/definitions?api-version={4}' -f $InstanceName, ":$Port", $CollectionName, $ProjectName, $ApiVersion } else { '{0}/{1}/{2}/_apis/build/definitions?api-version={3}' -f $InstanceName, $CollectionName, $ProjectName, $ApiVersion } $requestParameters = @{ Uri = $requestUrl Method = 'Get' ErrorAction = 'Stop' UseBasicParsing = $true } if ($Credential) { $requestParameters.Credential = $Credential } else { $requestParameters.Headers = @{ Authorization = Get-TfsAccessTokenString -PersonalAccessToken $PersonalAccessToken } } try { $result = Invoke-RestMethod @requestParameters } catch { Write-Error -ErrorRecord $_ } if ($result.value) { return $result.value } elseif ($result) { return $result } } |