Module/DevOps/Get-BCSDevOpsPipeline.ps1

<#
.SYNOPSIS
  Get a DevOps Pipeline from a project
 
.DESCRIPTION
  Gets a spceific of all pipelines in a DevOps project
 
.PARAMETER organisation
  DevOps Organisation Name, Default BrightComSolutions
  
.PARAMETER projectName
  DevOps Project Name
  
.PARAMETER sourcePat
  DevOps Pwesonal Access Token.
 
.EXAMPLE
  Get-BCSDevOpsPipelines -projectName "MyProjectName" -sourcePat (Get-BCSSecureString -InputString "MyDevOpsPat")
.NOTES
    Author: Mathias Stjernfelt
    Website: http://www.brightcom.se
#>


function Get-BCSDevOpsPipeline {
  Param (
    [Parameter(Mandatory = $false)]
    [string]$organisation = "BrightComSolutions",
    [Parameter(Mandatory = $true)]
    [string]$projectName,
    [Parameter(Mandatory = $true)]
    [string]$pipelineId,
    [Parameter(Mandatory = $true)]
    [securestring]$sourcePat
  )

  try {
    $fullOrgUrl = "https://dev.azure.com/$organisation";

    $Pat = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sourcePat))

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $encodedPat = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$pat"))
    $headers.Add("Authorization", "Basic $encodedPat")
    $headers.Add("Accept", "application/json")
    $headers.Add("Accept-Charset", "utf-8")
    
    $url = [uri]::EscapeUriString("$fullOrgUrl/$projectName/_apis/pipelines/$($pipelineId)?api-version=7.2-preview.1")

    $response = Invoke-RestMethod $url -Method 'GET' -Headers $headers
    $response
  }
  catch {
    throw $_.Exception;
  }
}

Export-ModuleMember -Function Get-BCSDevOpsPipeline