Public/Get-PSUADOProjectList.ps1

function Get-PSUADOProjectList {
    <#
    .SYNOPSIS
        Retrieves the list of Azure DevOps projects within the specified organization.
 
    .DESCRIPTION
        Uses Azure DevOps REST API to fetch all visible projects in an organization.
        Leverages environment variables if parameters are not supplied.
 
    .PARAMETER Organization
        The Azure DevOps organization name. If not provided, uses $env:ORGANIZATION.
 
    .EXAMPLE
        Get-PSUADOProjectList -Organization 'omgitsolutions'
 
    .EXAMPLE
        Get-PSUADOProjectList
 
    .OUTPUTS
        [PSCustomObject[]]
 
    .NOTES
        Author: Lakshmanachari Panuganti
        2 August 2025: Initial Development
 
    .LINK
        https://www.powershellgallery.com/packages/OMG.PSUtilities.AzureDevOps
        https://github.com/lakshmanachari-panuganti
        https://www.linkedin.com/in/lakshmanachari-panuganti/
    #>


    [CmdletBinding()]
    param (
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [string]$Organization = $env:ORGANIZATION,

        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [string]$PAT = $env:PAT
    )

    process {
        $headers = Get-PSUAdoAuthHeader -PAT $PAT
        $uri = "https://dev.azure.com/$Organization/_apis/projects?api-version=7.1-preview.4"

        try {
            $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get -ErrorAction Stop
            if ($response.value) {
                ConvertTo-CapitalizedObject -InputObject $response.value
            }

        }
        catch {
            $PSCmdlet.ThrowTerminatingError($_)
        }
    }
}