AzurePipelinesPS.psm1

$Script:PSModuleRoot = $PSScriptRoot
$Script:ModuleName = "AzurePipelinesPS"
$Script:APAppDataPath = [Environment]::GetFolderPath('ApplicationData')
$Script:ModuleDataRoot = (Join-Path -Path $Script:APAppDataPath -ChildPath $Script:ModuleName)
$Script:ModuleDataPath = (Join-Path -Path $Script:ModuleDataRoot -ChildPath "ModuleData.json")
if (-not (Test-Path $Script:ModuleDataRoot)) {New-Item -ItemType Directory -Path $Script:ModuleDataRoot -Force}
# Imported from [D:\_work\1\s\AzurePipelinesPS\Private]
# Get-APAgentPackage.ps1
Function Get-APAgentPackage
{
    <#
    .SYNOPSIS
 
    Returns available Azure Pipelines agent package versions download url.
 
    .DESCRIPTION
 
    Returns available Azure Pipelines agent package versions download url.
    The instance will provide a list of available compatible package versions and a url from which to download them.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Platform
 
    Operating system platform.
 
    .PARAMETER ApiVersion
 
    Version of the api to use.
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
     
    .INPUTS
 
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSCustomObject. Get-APAgentPackage returns all compatable agent package versions.
 
    .EXAMPLE
 
    Get-APAgentPackage -Platform 'ubuntu.14.04-x64' -Credential $pscredential
 
    .EXAMPLE
 
    Returns the 'windows' agent package url.
 
    Get-APAgentPackage -Platform 'Windows'
 
    .EXAMPLE
 
    Returns the 'ubuntu.16.04-x64' agent package url.
 
    Get-APAgentPackage -Platform 'ubuntu.16.04-x64'
 
    .LINK
 
    https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=vsts
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter()]
        [string]
        $Instance,

        [Parameter(Mandatory)]
        [ValidateSet('Windows', 'ubuntu.16.04-x64', 'ubuntu.14.04-x64')]
        [string]
        $Platform,

        [Parameter()]
        [string]
        $ApiVersion,

        [Parameter()]
        [pscredential]
        $Credential
    )
    begin
    {
    }
    Process
    {
        Switch -Wildcard ($ApiVersion)
        {
            '*5.*'
            {
                Switch ($Platform)
                {
                    'Windows'
                    {
                        Return 'https://vstsagentpackage.azureedge.net/agent/2.140.2/vsts-agent-win-x64-2.140.2.zip'
                    }
                    'ubuntu.16.04-x64'
                    {
                        Return 'https://vstsagentpackage.azureedge.net/agent/2.140.2/vsts-agent-linux-x64-2.140.2.tar.gz'
                    }
                    'ubuntu.14.04-x64'
                    {
                        Return 'https://vstsagentpackage.azureedge.net/agent/2.140.2/vsts-agent-linux-x64-2.140.2.tar.gz'
                    }
                }
            }
            Default
            {
                $apiEndpoint = Get-APApiEndpoint -ApiType 'packages-agent'
                [uri] $uri = Set-APUri -Instance $Instance -ApiEndpoint $apiEndpoint
                $invokeAPRestMethodSplat = @{
                    Method     = 'GET'
                    Uri        = $uri
                    Credential = $Credential
                }
                $results = Invoke-APRestMethod @invokeAPRestMethodSplat
                Switch ($Platform)
                {
                    'Windows'
                    {
                        Return $Results.Value | Where-Object { $Psitem.Platform -eq 'win7-x64' } | Select-Object -ExpandProperty 'downloadUrl'
                    }
                    'ubuntu.16.04-x64'
                    {
                        Return $Results.Value | Where-Object { $Psitem.Platform -eq 'ubuntu.16.04-x64' } | Select-Object -ExpandProperty 'downloadUrl'
                    }
                    'ubuntu.14.04-x64'
                    {
                        Return $Results.Value | Where-Object { $Psitem.Platform -eq 'ubuntu.14.04-x64' } | Select-Object -ExpandProperty 'downloadUrl'
                    }
                }
            }
        }
    }
}

# Get-APApiEndpoint.ps1
function Get-APApiEndpoint
{    
    <#
    .SYNOPSIS
 
    Returns the api uri endpoint.
 
    .DESCRIPTION
 
    Returns the api uri endpoint base on the api type.
 
    .PARAMETER ApiType
 
    Type of the api endpoint to use.
 
    .OUTPUTS
 
    String, The uri endpoint that will be used by Set-APUri.
 
    .EXAMPLE
 
    Returns the api endpoint for 'release-releases'
 
    Get-APApiEndpoint -ApiType release-releases
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/?view=vsts-rest-5.0
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory)]
        [string]
        $ApiType
    )

    begin
    {
    }

    process
    {
        Switch ($ApiType)
        {
            'build-builds'
            {
                Return '_apis/build/builds'
            }
            'build-buildId'
            {
                Return '_apis/build/builds/{0}'
            }
            'build-definitions'
            {
                Return '_apis/build/definitions'
            }
            'build-definitionId'
            {
                Return '_apis/build/definitions/{0}'
            }
            'packages-agent'
            {
                Return '_apis/distributedTask/packages/agent'
            }
            'policy-configurations'
            {
                Return '_apis/policy/configurations'
            }
            'policy-configurationId'
            {
                Return '_apis/policy/configurations/{0}'
            }
            'policy-types'
            {
                Return '_apis/policy/types'
            }
            'policy-typeId'
            {
                Return '_apis/policy/types/{0}'
            }
            'policy-evaluations'
            {
                Return '_apis/policy/evaluations'
            }
            'policy-evaluationId'
            {
                Return '_apis/policy/evaluations/{0}'
            }
            'policy-revisions'
            {
                Return '_apis/policy/configurations/{0}/revisions'                
            }
            'policy-revisionId'
            {
                Return '_apis/policy/configurations/{0}/revisions/{1}'
            }
            'release-releases'
            {
                Return '_apis/release/releases'
            }
            'release-definitions'
            {
                Return '_apis/release/definitions'
            }
            'release-definitionId'
            {
                Return '_apis/release/definitions/{0}'
            }
            'release-deployments'
            {
                Return '_apis/release/deployments'
            }
            'release-releaseId'
            {
                Return '_apis/release/releases/{0}'
            }
            'release-manualInterventionId'
            {
                Return '_apis/release/releases/{0}/manualinterventions/{1}'
            }
            'release-environmentId'
            {
                Return '_apis/release/releases/{0}/environments/{1}'
            }
            'release-taskId'
            {
                Return '_apis/release/releases/{0}/environments/{1}/deployPhases/{2}/tasks/{3}'
            }
            'release-logs'
            {
                Return '_apis/release/releases/{0}/environments/{1}/deployPhases/{2}/tasks/{3}/logs'
            }
            'release-approvals'
            {
                Return '_apis/release/approvals'
            }
            'release-approvalId'
            {
                Return '_apis/release/approvals/{0}'
            }
            'distributedtask-queues'
            {
                Return '_apis/distributedtask/queues'
            }
            'distributedtask-deploymentgroups'
            {
                Return '_apis/distributedtask/deploymentgroups'
            }
            'distributedtask-deploymentGroupId'
            {
                Return '_apis/distributedtask/deploymentgroups/{0}'
            }
            'distributedtask-targets'
            {
                Return '_apis/distributedtask/deploymentgroups/{0}/targets'
            }
            'distributedtask-targetId'
            {
                Return '_apis/distributedtask/deploymentgroups/{0}/targets/{1}'
            }
            'distributedtask-variablegroups'
            {
                Return '_apis/distributedtask/variablegroups'
            }
            'distributedtask-variablegroupId'
            {
                Return '_apis/distributedtask/variablegroups/{0}'
            }
            'git-repositories'
            {
                Return '_apis/git/repositories'
            }
            'git-repositoryId'
            {
                Return '_apis/git/repositories/{0}'
            }
            'git-refs'
            {
                Return '_apis/git/repositories/{0}/refs'
            }
            'git-pushes'
            {
                Return '_apis/git/repositories/{0}/pushes'
            }
            'git-pullRequests'
            {
                Return '_apis/git/repositories/{0}/pullrequests'
            }
            'project-projects'
            {
                Return '_apis/projects'
            }
            'taskgroup-taskgroups'
            {
                Return '_apis/distributedtask/taskgroups'
            }
            'feed-feeds'
            {
                Return '_apis/packaging/feeds'
            }
            'feed-feedId'
            {
                Return '_apis/packaging/feeds/{0}'
            }
            'feed-packages'
            {
                Return '_apis/packaging/feeds/{0}/packages'
            }
            'feed-packageId'
            {
                Return '_apis/packaging/feeds/{0}/packages/{1}'
            }
            'feed-packageVersion'
            {
                Return '_apis/packaging/feeds/{0}/nuget/packages/{1}/versions/{2}'
            }
            'feed-RBpackageVersion'
            {
                Return '_apis/packaging/feeds/{0}/nuget/RecycleBin/packages/{1}/versions/{2}'
            }
            'feed-packageContent'
            {
                Return '_apis/packaging/feeds/{0}/nuget/packages/{1}/versions/{2}/content'
            }
            'graph-userId'
            {
                Return '_apis/graph/users/{0}'
            }
            'graph-users'
            {
                Return '_apis/graph/users'
            }
            'graph-groupId'
            {
                Return '_apis/graph/groups/{0}'
            }
            'graph-groups'
            {
                Return '_apis/graph/groups'
            }
            'graph-storagekeys'
            {
                Return '_apis/graph/storagekeys/{0}'
            }
            'groupentitlements-entitlements'
            {
                Return '_apis/groupentitlements'
            }
            'team-teams'
            {
                Return '_apis/teams'
            }
            'git-deletedrepositories'
            {
                Return '_apis/git/deletedrepositories'
            }
            'git-recycleBin'
            {
                Return '_apis/git/recycleBin/repositories'
            }
            'git-items'
            {
                Return '_apis/git/repositories/{0}/items'
            }
            'extensionmanagement-installedextensions'
            {
                Return '_apis/extensionmanagement/installedextensions'
            }
            'extensionmanagement-installedextensionsbyname'
            {
                Return '_apis/extensionmanagement/installedextensionsbyname/{0}/{1}'
            }
            'dashboard-dashboards'
            {
                Return '_apis/dashboard/dashboards'
            }
            'dashboard-dashboardId'
            {
                Return '_apis/dashboard/dashboards/{0}'
            }
            'dashboard-widgets'
            {
                Return '_apis/dashboard/dashboards/{0}/widgets'
            }
            'dashboard-widgetId'
            {
                Return '_apis/dashboard/dashboards/{0}/widgets/{1}'
            }
            'packaging-feedName'
            {
                Return '_packaging/{0}/nuget/v2'
            }
            'securitynamespaces-securityNamespaceId'
            {
                Return '_apis/securitynamespaces/{0}'
            }
            'sourceProviders-sourceproviders'
            {
                Return '_apis/sourceproviders'
            }
            'sourceProviders-branches'
            {
                Return '_apis/sourceProviders/{0}/branches'
            }
            'notification-subscriptions'
            {
                Return '_apis/notification/subscriptions'
            }
            'notification-subscriptionId'
            {
                Return '_apis/notification/subscriptions/{0}'
            }
            'notification-subscriptionTemplates'
            {
                Return '_apis/notification/subscriptiontemplates'
            }
            'accesscontrollists-securityNamespaceId'
            {
                Return '_apis/accesscontrollists/{0}'
            }
            'serviceendpoint-endpoints'
            {
                Return '_apis/serviceendpoint/endpoints'
            }
            'serviceendpoint-endpointId'
            {
                Return '_apis/serviceendpoint/endpoints/{0}'
            }
            'serviceendpoint-types'
            {
                Return '_apis/serviceendpoint/types'
            }
            'serviceendpoint-executionhistory'
            {
                Return '_apis/serviceendpoint/{0}/executionhistory'
            }
            'tokenadmin-subjectDescriptor'
            {
                Return '_apis/tokenadmin/personalaccesstokens/{0}'
            }
            default
            {
                Write-Error "[$($MyInvocation.MyCommand.Name)]: [$ApiType] is not supported" -ErrorAction Stop
            }
        }
    }

    end
    {
    }
}

# Set-APAuthenticationType.ps1
function Set-APAuthenticationType
{    
    <#
    .SYNOPSIS
 
    Sets the authentication type used by Invoke-APRestMethod.
 
    .DESCRIPTION
 
    Sets the authentication type used by Invoke-APRestMethod.
    Default authentication will use the pesonal access token that is stored in session data, unless a credential is provided.
 
    .PARAMETER InputObject
     
    The splat parameters used by Invoke-APRestMethod.
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
     
    .OUTPUTS
 
    PSObject, The modifed inputobject.
 
    .EXAMPLE
 
    Set-APAuthenticationType -InputObject $inputObject
 
    .EXAMPLE
 
    Sets the AP authentication to the credential provided for the input object.
     
    Set-APAuthenticationType -InputObject $inputObject -Credential $pscredential
 
    .EXAMPLE
 
    Sets the AP authentication to the personal access token provided for the input object.
     
    Set-APAuthenticationType -InputObject $inputObject -PersonalAccessToken $mySecureToken
 
    .LINK
 
    https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/authentication-guidance?view=vsts
    #>

    [CmdletBinding()]
    param 
    (
        [Parameter(Mandatory)]
        [PSObject]
        $InputObject,

        [Parameter()]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter()]
        [pscredential]
        $Credential
    )

    begin
    {
    }

    process
    {
        If ($Credential)
        {
            Write-Verbose "[$($MyInvocation.MyCommand.Name)]: Authenticating with the provided credential."
            $InputObject.Credential = $Credential
        }
        ElseIf ($PersonalAccessToken)
        {
            Write-Verbose "[$($MyInvocation.MyCommand.Name)]: Authenticating with the stored personal access token."
            $PersonalAccessTokenToken = Unprotect-APSecurePersonalAccessToken -PersonalAccessToken $PersonalAccessToken
            $encodedPersonalAccessToken = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$PersonalAccessTokenToken"))
            $InputObject.Headers = @{Authorization = "Basic $encodedPersonalAccessToken" }
        }
        Else
        {
            Write-Verbose "[$($MyInvocation.MyCommand.Name)]: Authenticating with default credentials"
            $InputObject.UseDefaultCredentials = $true
        }
    }

    end
    {
        Return $InputObject
    }
}

# Set-APQueryParameters.ps1
function Set-APQueryParameters
{    
    <#
    .SYNOPSIS
 
    Returns the formated query parameter string.
 
    .DESCRIPTION
 
    Returns the formated query parameter string.
 
    .PARAMETER InputObject
     
    The PS bound parameters.
 
    .OUTPUTS
 
    String, The formated query parameter string.
 
    .EXAMPLE
 
    Sets the AP query parameters for the input object.
 
    Set-APQueryParameters -InputObject $PSBoundParameters
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/?view=vsts-rest-5.0
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter()]
        [object]
        $InputObject
    )

    begin
    {
    }

    process
    {
        $nonQueryParams = @(
            'Instance'
            'Collection'
            'Project'
            'ApiVersion'
            'PersonalAccessToken'
            'Session'
            'Credential'
            'Verbose'
            'Debug'
            'ErrorAction'
            'WarningAction' 
            'InformationAction' 
            'ErrorVariable' 
            'WarningVariable' 
            'InformationVariable' 
            'OutVariable' 
            'OutBuffer'
            'UserDescriptor'
            'GroupDescriptor'
            'PersonalAccessToken'
        )
        $queryParams = Foreach ($key in $InputObject.Keys)
        {
            If ($nonQueryParams -contains $key)
            {
                Continue
            }
            ElseIf ($key -eq 'Top')
            {
                "`$$key=$($InputObject.$key)"
            }
            ElseIf ($key -eq 'Mine')
            {
                "`$$key=$($InputObject.$key)"
            }
            ElseIf ($key -Match '[A-Za-z0-9]+_[A-Za-z0-9]+') # keys with underscores convert to dot-delimited
            {
                $fixedKey = $key.Replace("_", ".")
                "$fixedKey=$($InputObject.$key)"
            }
            ElseIf ($InputObject.$key.count)
            {
                "$key={0}" -f ($InputObject.$key -join ',')
            }
            else
            {
                "$key=$($InputObject.$key)"                    
            }
        }
        Return ($queryParams -join '&')
    }

    end
    {
    }
}

# Set-APUri.ps1
function Set-APUri
{
    <#
    .SYNOPSIS
 
    Sets the uri used by Invoke-APRestMethod.
 
    .DESCRIPTION
 
    Sets the uri used by Invoke-APRestMethod.
 
    .PARAMETER Instance
 
    The Team Services account or TFS server.
 
    .PARAMETER Collection
 
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
 
    Project ID or project name.
 
    .PARAMETER Query
 
    Url query parameter.
 
    .PARAMETER ApiEndpoint
 
    The api endpoint provided by Get-APApiEndpoint.
 
    .PARAMETER ApiVersion
 
    Version of the api to use.
 
    .OUTPUTS
 
    Uri, The uri that will be used by Invoke-APRestMethod.
 
    .EXAMPLE
 
    Set-APUri -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiEndpoint _apis/Release/releases/4 -ApiVersion '5.0-preview.6'
 
    .EXAMPLE
 
    Set-APUri -ApiEndpoint _apis/Release/releases/4 -ApiVersion '5.0-preview.6' -Query 'project=myFirstProject&isdeleted=true&expand=environments'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/?view=vsts-rest-5.0
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter()]
        [uri]
        $Instance,

        [Parameter()]
        [string]
        $Collection,

        [Parameter()]
        [string]
        $Project,

        [Parameter()]
        [string]
        $Query,

        [Parameter(Mandatory)]
        [string]
        $ApiEndpoint,

        [Parameter()]
        [string]
        $ApiVersion
    )

    begin
    {
    }

    process
    {
        If ($ApiVersion -match '5.*' -and ($Instance.Host -eq 'dev.azure.com' -or $Instance.Host -like '*.visualstudio.com'))
        {
            # Api endpoint matches release
            If ($ApiEndpoint -match 'release')
            {
                If ($Instance.AbsoluteUri -and $Collection -and $Project -and $Query)
                {
                    # Append vsrm prefix to instance with query
                    return '{0}{1}/{2}/{3}?{4}&api-version={5}' -f $Instance.AbsoluteUri.replace($Instance.Host, "vsrm.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $Query, $ApiVersion
                }
                ElseIf ($Instance.AbsoluteUri -and $Collection -and $Project)
                {
                    # Append vsrm prefix to instance without query
                    return '{0}{1}/{2}/{3}?api-version={4}' -f $Instance.AbsoluteUri.replace($Instance.Host, "vsrm.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $ApiVersion
                }
            }
            # Api endpoint matches feeds
            If ($ApiEndpoint -match 'feeds')
            {
                If ($ApiEndpoint -match 'versions')
                {
                    # Append pkgs prefix to instance with query
                    return '{0}{1}/{2}/{3}?{4}&api-version={5}' -f $Instance.AbsoluteUri.replace($Instance.Host, "pkgs.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $Query, $ApiVersion
                }
                If ($Instance.AbsoluteUri -and $Collection -and $Query)
                {
                    # Append feeds prefix to instance with query
                    return '{0}{1}/{2}/{3}?{4}&api-version={5}' -f $Instance.AbsoluteUri.replace($Instance.Host, "feeds.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $Query, $ApiVersion
                }
                ElseIf ($Instance.AbsoluteUri -and $Collection)
                {
                    # Append feeds prefix to instance without query
                    return '{0}{1}/{2}/{3}?api-version={4}' -f $Instance.AbsoluteUri.replace($Instance.Host, "feeds.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $ApiVersion
                }
            }
            # Api endpoint matches graph
            If ($ApiEndpoint -match 'graph')
            {
                If ($Instance.AbsoluteUri -and $Collection -and $Query)
                {
                    # Append vssps prefix to instance with query
                    return '{0}{1}/{2}/{3}?{4}&api-version={5}' -f $Instance.AbsoluteUri.replace($Instance.Host, "vssps.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $Query, $ApiVersion
                }
                ElseIf ($Instance.AbsoluteUri -and $Collection)
                {
                    # Append vssps prefix to instance without query
                    return '{0}{1}/{2}/{3}?api-version={4}' -f $Instance.AbsoluteUri.replace($Instance.Host, "vssps.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $ApiVersion
                }
            }
            # Api endpoint matches tokenadmin
            If ($ApiEndpoint -match 'tokenadmin')
            {
                If ($Instance.AbsoluteUri -and $Collection -and $Query)
                {
                    # Append vssps prefix to instance with query
                    return '{0}{1}/{2}?{3}&api-version={4}' -f $Instance.AbsoluteUri.replace($Instance.Host, "vssps.$($Instance.Host)"), $Collection, $ApiEndpoint, $Query, $ApiVersion
                }
                ElseIf ($Instance.AbsoluteUri -and $Collection)
                {
                    # Append vssps prefix to instance without query
                    return '{0}{1}/{2}?api-version={3}' -f $Instance.AbsoluteUri.replace($Instance.Host, "vssps.$($Instance.Host)"), $Collection, $ApiEndpoint, $ApiVersion
                }
            }
            # Api endpoint matches groupentitlements
            If ($ApiEndpoint -match 'groupentitlements')
            {
                If ($Instance.AbsoluteUri -and $Collection)
                {
                    # Append vsaex prefix to instance without query
                    return '{0}{1}/{2}/{3}?api-version={4}' -f $Instance.AbsoluteUri.replace($Instance.Host, "vsaex.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $ApiVersion
                }
            }
            # Api endpoint matches extensionmanagement
            If ($ApiEndpoint -match 'extensionmanagement')
            {
                If ($Instance.AbsoluteUri -and $Collection -and $Query)
                {
                    # Append extmgmt prefix to instance with query
                    return '{0}{1}/{2}/{3}?{4}&api-version={5}' -f $Instance.AbsoluteUri.replace($Instance.Host, "extmgmt.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $Query, $ApiVersion
                }
                ElseIf ($Instance.AbsoluteUri -and $Collection)
                {
                    # Append extmgmt prefix to instance without query
                    return '{0}{1}/{2}/{3}?api-version={4}' -f $Instance.AbsoluteUri.replace($Instance.Host, "extmgmt.$($Instance.Host)"), $Collection, $Project, $ApiEndpoint, $ApiVersion
                }
            }
            # Api endpoint matches packaging
            If ($ApiEndpoint -match 'packaging')
            {
                If ($Instance.AbsoluteUri -and $Collection)
                {
                    # Append pkgs prefix to instance without query and api version
                    return '{0}{1}/{2}' -f $Instance.AbsoluteUri.replace($Instance.Host, "pkgs.$($Instance.Host)"), $Collection, $ApiEndpoint
                }
            }
        }
        If ($Instance.AbsoluteUri -and $Collection -and $Project -and $ApiEndpoint -and $ApiVersion -and $Query)
        {
            return '{0}{1}/{2}/{3}?{4}&api-version={5}' -f $Instance.AbsoluteUri, $Collection, $Project, $ApiEndpoint, $Query, $ApiVersion
        }
        If ($Instance.AbsoluteUri -and $Collection -and $ApiEndpoint -and $ApiVersion -and $Query)
        {
            return '{0}{1}/{2}?{3}&api-version={4}' -f $Instance.AbsoluteUri, $Collection, $ApiEndpoint, $Query, $ApiVersion
        }
        ElseIf ($Instance.AbsoluteUri -and $Collection -and $Project -and $ApiEndpoint -and $ApiVersion)
        {
            return '{0}{1}/{2}/{3}?api-version={4}' -f $Instance.AbsoluteUri, $Collection, $Project, $ApiEndpoint, $ApiVersion
        }
        ElseIf ($Instance.AbsoluteUri -and $Collection -and $ApiEndpoint -and $ApiVersion)
        {
            return '{0}{1}/{2}?api-version={3}' -f $Instance.AbsoluteUri, $Collection, $ApiEndpoint, $ApiVersion
        }
        ElseIf ($Instance.AbsoluteUri -and $ApiEndpoint)
        {
            return '{0}{1}' -f $Instance.AbsoluteUri, $ApiEndpoint
        }
    }

    end
    {
    }
}

# Unprotect-APSecurePersonalAccessToken.ps1
Function Unprotect-APSecurePersonalAccessToken
{
    <#
    .SYNOPSIS
 
    Returns decrypted personal access token.
 
    .DESCRIPTION
 
    Returns decrypted personal access token that is stored in the session data.
 
    .PARAMETER PersonalAccessToken
 
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
         
    .OUTPUTS
 
    String, unsecure personal access token.
 
    .EXAMPLE
 
    Unprotects the personal access token from secure string to plain text.
 
    Unprotect-SecurePersonalAccessToken -PersonalAccessToken $mySecureToken
 
    .LINK
 
    https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/authentication-guidance?view=vsts
    #>


    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory)]
        [Security.SecureString]
        $PersonalAccessToken
    )
    Process
    {
        $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PersonalAccessToken)
        $plainText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
        Return $plainText
    }
}

# Imported from [D:\_work\1\s\AzurePipelinesPS\Public]
# Add-APDeploymentGroup.ps1
function Add-APDeploymentGroup
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipeline deployment group.
 
    .DESCRIPTION
 
    Creates an Azure Pipeline deployment group.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
     
    Name of the deployment group.
 
    .PARAMETER Description
     
    Description of the deployment group.
     
    .PARAMETER PoolId
     
    Identifier of the deployment pool in which deployment agents are registered.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines deployment group.
 
    .EXAMPLE
 
    Creates the AP deployment group 'myGroup' for the project 'myFirstProject'
 
    Add-APDeploymentGroup -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -Name 'myGroup'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/deploymentgroups/add?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $Name,

        [Parameter()]
        [string]
        $Description,

        [Parameter()]
        [string]
        $PoolId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken                
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = @{
            Name        = $Name
            Description = $Description
            PoolId      = $PoolId
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-deploymentGroupId') -f $DeploymentGroupID
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Add-APVariableGroup.ps1
function Add-APVariableGroup
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipeline variable group.
 
    .DESCRIPTION
 
    Creates an Azure Pipeline variable group.
 
  .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
     
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Description
     
    Sets description of the variable group.
  
    .PARAMETER Name
     
    Sets name of the variable group.
 
    .PARAMETER Variables
     
    Sets variables contained in the variable group.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines variable group.
 
    .EXAMPLE
 
    $varibales = @{
        Var1 = 'updated val1'
        Var2 = 'updated val2'
    }
    $addAPVariableGroupSplat = @{
        Description = 'my variable group'
        Name = 'myVariableGroup'
        Variables = $varibales
        Instance = 'https://dev.azure.com'
        Collection = 'myCollection'
        Project = 'myFirstProject'
    }
    Add-APVariableGroup @addAPVariableGroupSplat
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/variablegroups/add?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $Name,

        [Parameter()]
        [string]
        $Description,

        [Parameter(Mandatory)]
        [object]
        $Variables
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        If ($Variables.GetType().Name -eq 'hashtable')
        {
            $_variables = @{ }
            Foreach ($token in $Variables.Keys)
            {
                $_variables.$token = @{
                    Value = $Variables.$token
                }
            }
        }
        else 
        {
            $_variables = $Variables    
        }
        $body = @{
            Name        = $Name
            Description = $Description
            Type        = 'Vsts'
            Variables   = $_variables
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'distributedtask-variablegroups'
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Add-APWidget.ps1
function Add-APWidget
{
    <#
    .SYNOPSIS
 
    Adds an Azure Pipeline widget to a dashboard.
 
    .DESCRIPTION
 
    Adds an Azure Pipeline widget to a dashboard.
    The widget can object can be retrieved by using Get-APWidget and modifying the position.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Dashboard
     
    ID of the dashboard to read.
 
    .PARAMETER Widget
 
    The widget object, the object can be retrived using Get-APWidgetList.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines widget.
 
    .EXAMPLE
 
    $widget = Get-APWidget -Session 'mySession' -Dashboard '51485dc189cd1-c894-41984-a77a-8sw4xc94' -Widget '580583f2-ce98-4890-a77a-853ee419c196'
    $widget.position.row = 2 # Update the position to an empty row
    Add-APWidget -Session 'mySession' -Dashboard '51485dc189cd1-c894-41984-a77a-8sw4xc94' -Widget $widget
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/dashboard/widgets/create?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $Dashboard,

        [Parameter(Mandatory)]
        [object]
        $Widget
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $null = $Widget.psobject.Properties.Remove('Id')
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'dashboard-widgets') -f $Dashboard
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $Widget
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Find-APPSModule.ps1
function Find-APPSModule
{
    <#
    .SYNOPSIS
 
    Finds a module from an Azure Pipelines feed.
 
    .DESCRIPTION
 
    Finds a module from an Azure Pipelines feed using the personal access token from the session configuration.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
 
    pecifies the names of modules to search for in the repository. A comma-separated list of module names is accepted. Wildcards are accepted.
 
    .PARAMETER Repository
 
    Use the Repository parameter to specify which repository is used to download and install a module. Used when multiple repositories are registered. Specifies the name of a registered repository in the Install-APPSModule command. To register a repository, use Register-APPSRepository. To display registered repositories, use Get-PSRepository.
 
    .PARAMETER RequiredVersion
 
    Specifies the exact version of a single module to install. If there is no match in the repository for the specified version, an error is displayed. If you want to install multiple modules, you cannot use RequiredVersion.
 
    .PARAMETER AllVersions
 
    Specifies to include all versions of a module in the results. You cannot use the AllVersions parameter with the RequiredVersion parameters.
 
    .PARAMETER AllowPrerelease
 
    Includes in the results modules marked as a pre-release.
 
    .PARAMETER Command
 
    Specifies an array of commands to find in modules. A command can be a function or workflow.
 
    .PARAMETER DscResource
 
    Specifies the name, or part of the name, of modules that contain DSC resources. Per PowerShell conventions, performs an OR search when you provide multiple arguments.
 
    .PARAMETER Filter
 
    Specifies a filter based on the PackageManagement provider-specific search syntax. For NuGet modules, this parameter is the equivalent of searching by using the Search bar on the PowerShell Gallery website.
 
    .PARAMETER IncludeDependencies
 
    Indicates that this operation includes all modules that are dependent upon the module specified in the Name parameter.
 
    .PARAMETER AllVersions
 
    Specifies to include all versions of a module in the results. You cannot use the AllVersions parameter with the MinimumVersion, MaximumVersion, or RequiredVersion parameters.
 
    .PARAMETER MaximumVersion
 
    Specifies the maximum, or latest, version of the module to include in the search results. MaximumVersion and RequiredVersion cannot be used in the same command.
 
    .PARAMETER MinimumVersion
 
    Specifies the minimum version of the module to include in results. MinimumVersion and RequiredVersion cannot be used in the same command.
 
    .PARAMETER Tag
 
    Specifies an array of tags. Example tags include DesiredStateConfiguration, DSC, DSCResourceKit, or PSModule.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines Module.
 
    .EXAMPLE
     
    .LINK
 
    https://docs.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-6
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string[]]
        $Name,

        [Parameter()]
        [string[]]
        $Repository,

        [Parameter()]
        [string]
        $RequiredVersion,

        [Parameter()]
        [switch]
        $AllVersions,

        [Parameter()]
        [switch]
        $AllowPrerelease,

        [Parameter()]
        [string]
        $Command,

        [Parameter()]
        [string]
        $DscResource,
        
        [Parameter()]
        [string]
        $Filter,

        [Parameter()]
        [switch]
        $IncludeDependencies,

        [Parameter()]
        [string]
        $MaximumVersion,
        
        [Parameter()]
        [string]
        $MinimumVersion,

        [Parameter()]
        [string[]]
        $Tag
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
            }
        }
    }
        
    process
    {
        If ($PersonalAccessToken)
        {
            $Credential = [pscredential]::new('NA', $PersonalAccessToken)
        }
        $findModuleSplat = @{
            Name       = $Name
            Credential = $Credential
        }
        If ($Repository)
        {
            $findModuleSplat.Repository = $Repository 
        }
        If ($Filter)
        {
            $findModuleSplat.Filter = $Filter 
        }
        If ($IncludeDependencies)
        {
            $findModuleSplat.IncludeDependencies = $IncludeDependencies 
        }
        If ($AllVersions)
        {
            $findModuleSplat.AllVersions = $AllVersions 
        }
        If ($AllowPrerelease)
        {
            $findModuleSplat.AllowPrerelease = $AllowPrerelease 
        }
        If ($Proxy)
        {
            $findModuleSplat.Proxy = $Proxy 
        }
        If ($ProxyCredential)
        {
            $findModuleSplat.ProxyCredential = $ProxyCredential 
        }
        If ($Command)
        {
            $findModuleSplat.Command = $Command 
        }
        If ($RequiredVersion)
        {
            $findModuleSplat.RequiredVersion = $RequiredVersion 
        }
        If ($MinimumVersion)
        {
            $findModuleSplat.MinimumVersion = $MinimumVersion 
        }
        If ($MaximumVersion)
        {
            $findModuleSplat.MaximumVersion = $MaximumVersion 
        }
        If ($DscResource)
        {
            $findModuleSplat.DscResource = $DscResource 
        }
        If ($Tag)
        {
            $findModuleSplat.Tag = $Tag 
        }
        Find-Module @findModuleSplat
    }
    
    end
    {
    }
}
# Format-APTemplate.ps1
Function Format-APTemplate
{
    <#
    .SYNOPSIS
 
    Replaces tokens in a json template.
 
    .DESCRIPTION
 
    Replaces tokens in a json template. The json template tokens should be unique strings like '%Project%' or '__Collection__'.
    By passing key value pairs with the InputObject parameter @{'%Project% = 'myProject'} the tokens will be replaced with the values.
    Templates can be created by using Get-APBuildDefinition or Get-APReleaseDefinition and tokenizing it.
 
    .PARAMETER Path
     
    Path to the build/release json template that contains tokens.
     
    .PARAMETER InputObject
     
    Object, that contains key value pairs for token replacement.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, Azure Pipelines build/release template. Pass the template to Publish-APBuild or Publish-APRelease.
 
    .EXAMPLE
 
    Replaces all instances of '%Project%' with 'myProject' for the input object.
 
    $inputObject = @{
        %Project% = 'myProject'
    }
    Format-APTemplate -Path '.\myTemplate.json' -InputObject $inputObject
    #>

    Param
    (
        [Parameter(Mandatory)]
        [string]
        $Path,

        [Parameter(Mandatory)]
        [object]
        $InputObject
    )

    Begin
    {
    }
    Process
    {        
        $templateJson = Get-Content -Path $Path -Raw  
        $InputObject.Keys | ForEach-Object -Process { $templateJson = $templateJson -replace $_, $InputObject.Item($_) }
        ConvertFrom-Json -Inputobject $templateJson 
    }
}
# Get-APAccessControlListList.ps1
function Get-APAccessControlListList
{
    <#
    .SYNOPSIS
 
    Returns a list of access control lists.
 
    .DESCRIPTION
 
    Returns a list of access control lists based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER SecurityNamespaceId
 
    Security namespace identifier.
 
    .PARAMETER Token
 
    Security token.
 
    .PARAMETER Descriptors
 
    An optional filter string containing a list of identity descriptors separated by ',' whose ACEs should be retrieved. If this is left null, entire ACLs will be returned.
 
    .PARAMETER IncludeExtendedInfo
 
    If true, populate the extended information properties for the access control entries contained in the returned lists.
 
    .PARAMETER Recurse
 
    If true and this is a hierarchical namespace, return child ACLs of the specified token.
 
    .PARAMETER Token
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines security namespace(s)
 
    .EXAMPLE
 
    Returns all access control lists
 
    Get-APBuildList -Session 'mySession'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/security/access%20control%20lists/query?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $SecurityNamespaceId,

        [Parameter()]
        [string]
        $Token,

        [Parameter()]
        [string]
        $Descriptors,

        [Parameter()]
        [bool]
        $IncludeExtendedInfo,

        [Parameter()]
        [bool]
        $Recurse
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'accesscontrollists-securityNamespaceId') -f $SecurityNamespaceId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APApiVersion.ps1
function Get-APApiVersion
{    
    <#
    .SYNOPSIS
 
    Returns the api version available for the TFS version provided.
 
    .DESCRIPTION
 
    Returns the api version available for the TFS version provided.
 
    .PARAMETER Version
     
    TFS version, this will provide the module with the api version mappings.
 
    .OUTPUTS
 
    String, The api version available for the TFS version provided.
 
    .EXAMPLE
 
    Returns the APApiVersion for 'vNext'
     
    Get-APApiVersion -Version 'vNext'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-5.0&viewFallbackFrom=vsts-rest-5.0#api-and-tfs-version-mapping
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter()]
        [string]
        $Version
    )

    begin
    {
    }

    process
    {
        Switch ($Version)
        {
            'vNext'
            {
                Return '5.0-preview'
            }
            '2018 Update 2'
            {
                Return '4.0-preview'
            }
            '2018 RTW'
            {
                Return '4.0'
            }
            '2017 Update 2'
            {
                Return '3.2'
            }
            '2017 Update 1'
            {
                Return '3.1'
            }
            '2017 RTW'
            {
                Return '3.0'
            } 
            '2015 Update 4'
            {
                Return '2.3'
            } 
            '2015 Update 3'
            {
                Return '2.3'
            } 
            '2015 Update 2'
            {
                Return '2.2'
            } 
            '2015 Update 1'
            {
                Return '2.1'
            } 
            '2015 RTW'
            {
                Return '2.0'
            }
            default
            {
                Write-Error "[$($MyInvocation.MyCommand.Name)]: [$Version] is not supported, run 'Save-APSession -Version' to populate module data. " -ErrorAction Stop
            }
        }
    }

    end
    {
    }
}

# Get-APApprovalList.ps1
function Get-APApprovalList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline approvals.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline approvals based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER AssignedToFilter
 
    Approvals assigned to this user.
 
    .PARAMETER StatusFilter
 
    Approvals with this status. Default is 'pending'.
 
    .PARAMETER ReleaseIdsFilter
 
    Approvals for release id(s) mentioned in the filter. Multiple releases can be mentioned by separating them with ',' e.g. releaseIdsFilter=1,2,3,4.
 
    .PARAMETER TypeFilter
 
    Approval with this type.
 
    .PARAMETER Top
 
    Number of approvals to get. Default is 50.
 
    .PARAMETER ContinuationToken
 
    Gets the approvals after the continuation token provided.
 
    .PARAMETER QueryOrder
 
    Gets the results in the defined order of created approvals. Default is 'descending'.
 
    .PARAMETER IncludeMyGroupApprovals
     
    'true' to include my group approvals. Default is 'false'.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines approval(s)
 
    .EXAMPLE
 
    Returns an AP approval list for the current user in the 'myFirstProject'.
 
    Get-APApprovalList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ApiVersion 5.0-preview
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/approvals/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $AssignedToFilter,

        [Parameter()]
        [ValidateSet('approved', 'canceled', 'pending', 'reassigned', 'rejected', 'skipped', 'undefined')]
        [string[]]
        $StatusFilter,

        [Parameter()]
        [string[]]
        $ReleaseIdsFilter,

        [Parameter()]
        [ValidateSet('all', 'postDeploy', 'preDeploy', 'undefined')]
        [string]
        $TypeFilter,

        [Parameter()]
        [int]
        $Top,   
        
        [Parameter()]
        [int]
        $ContinuationToken,

        [Parameter()]
        [ValidateSet('ascending', 'descending')]
        [string]
        $QueryOrder,

        [Parameter()]
        [bool]
        $IncludeMyGroupApprovals
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'release-approvals'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APBuild.ps1
function Get-APBuild
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline build.
 
    .DESCRIPTION
 
    Returns Azure Pipeline build based by build id.
    The id can be retrieved by using Get-APBuildList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER BuildId
 
    The ID of the build.
 
    .PARAMETER PropertyFilters
     
    Undocumented
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s).
 
    .EXAMPLE
 
    Returns the build with the id of '7' for the 'myFirstProject.
 
    Get-APBuild -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -BuildId 7
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/builds/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
        
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $BuildId,

        [Parameter()]
        [string]
        $PropertyFilters
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'build-buildId') -f $BuildId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APBuildDefinition.ps1
function Get-APBuildDefinition
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline build definitions.
 
    .DESCRIPTION
 
    Returns Azure Pipeline build definitions by definition id.
    The id can be retrieved by using Get-APBuildDefinitionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DefinitionID
 
    The ID of the definition.
 
    .PARAMETER Revision
 
    The revision number to retrieve. If this is not specified, the latest version will be returned.
 
    .PARAMETER MinMetricsTime
 
    If specified, indicates the date from which metrics should be included.
 
    .PARAMETER PropertyFilters
 
    A comma-delimited list of properties to include in the results.
 
    .PARAMETER IncludeLatestBuilds
 
    Indicates whether to include or exclude the latest builds.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns the build definition with the definition id of '7' for 'myFirstProject'.
 
    Get-APBuild -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DefinitionID 7
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/definitions/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $DefinitionID,

        [Parameter()]
        [int]
        $Revision,

        [Parameter()]
        [datetime]
        $MinMetricsTime,
       
        [Parameter()]
        [string[]]
        $PropertyFilters,

        [Parameter()]
        [switch]
        $IncludeLatestBuilds
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {

        $apiEndpoint = (Get-APApiEndpoint -ApiType 'build-definitionId') -f $DefinitionID
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APBuildDefinitionList.ps1
function Get-APBuildDefinitionList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline build definitions.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline build definitions based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
     
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER TaskIdFilter
 
    If specified, filters to definitions that use the specified task.
 
    .PARAMETER IncludeLatestBuilds
 
    Indicates whether to return the latest and latest completed builds for this definition.
 
    .PARAMETER IncludeAllProperties
 
    Indicates whether to return the latest and latest completed builds for this definition.
 
    .PARAMETER NotBuiltAfter
 
    If specified, filters to definitions that do not have builds after this date.
 
    .PARAMETER BuiltAfter
 
    If specified, filters to definitions that have builds after this date.
 
    .PARAMETER Path
 
    If specified, filters to definitions under this folder.
 
    .PARAMETER DefinitionIds
 
    A comma-delimited list that specifies the IDs of definitions to retrieve.
 
    .PARAMETER MinMetricsTime
 
    If specified, indicates the date from which metrics should be included.
 
    .PARAMETER ContinuationToken
 
    A continuation token, returned by a previous call to this method, that can be used to return the next set of definitions.
 
    .PARAMETER Top
 
    The maximum number of definitions to return.
 
    .PARAMETER QueryOrder
 
    Indicates the order in which definitions should be returned.
 
    .PARAMETER RepositoryType
 
    If specified, filters to definitions that have a repository of this type.
 
    .PARAMETER RepositoryId
 
    A repository ID. If specified, filters to definitions that use this repository.
 
    .PARAMETER Name
 
    If specified, filters to definitions whose names match this pattern.
 
    .PARAMETER YamlFilename
 
    If specified, filters to YAML definitions that match the given filename.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns the AP build definition list for 'myFirstProject'.
 
    Get-APBuildDefinitionList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/definitions/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $TaskIdFilter,

        [Parameter()]
        [bool]
        $IncludeLatestBuilds,

        [Parameter()]
        [bool]
        $IncludeAllProperties,

        [Parameter()]
        [datetime]
        $NotBuiltAfter,

        [Parameter()]
        [datetime]
        $BuiltAfter,

        [Parameter()]
        [string]
        $Path,

        [Parameter()]
        [int[]]
        $DefinitionIds,

        [Parameter()]
        [datetime]
        $MinMetricsTime,

        [Parameter()]
        [string]
        $ContinuationToken,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [string]
        [ValidateSet('ascending', 'descending')]
        $QueryOrder,

        [Parameter()]
        [string]
        $RepositoryType,

        [Parameter()]
        [string]
        $RepositoryId,

        [Parameter()]
        [string]
        $Name,

        [Parameter()]
        [string]
        $YamlFilename
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'build-definitions'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APBuildList.ps1
function Get-APBuildList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline builds.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline builds based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER RepositoryId
 
    If specified, filters to builds that built from this repository.
 
    .PARAMETER BuildIds
 
    A comma-delimited list that specifies the IDs of builds to retrieve.
 
    .PARAMETER BranchName
 
    If specified, filters to builds that built branches that built this branch.
 
    .PARAMETER QueryOrder
 
    The order in which builds should be returned.
 
    .PARAMETER DeletedFilter
 
    Indicates whether to exclude, include, or only return deleted builds.
 
    .PARAMETER MaxBuildsPerDefinition
 
    The maximum number of builds to return per definition.
 
    .PARAMETER ContinuationToken
 
    A continuation token, returned by a previous call to this method, that can be used to return the next set of builds.
 
    .PARAMETER Top
 
    The maximum number of builds to return.
 
    .PARAMETER Properties
 
    A comma-delimited list of properties to retrieve.
 
    .PARAMETER TagFilters
 
    A comma-delimited list of tags. If specified, filters to builds that have the specified tags.
 
    .PARAMETER ResultFilter
     
    If specified, filters to builds that match this result.
 
    .PARAMETER StatusFilter
 
    If specified, filters to builds that match this status.
 
    .PARAMETER ReasonFilter
 
    If specified, filters to builds that match this reason.
 
    .PARAMETER RequestedFor
     
    If specified, filters to builds requested for the specified user.
 
    .PARAMETER MaxTime
         
    If specified, filters to builds requested for the specified user.
 
    .PARAMETER MinTime
 
    If specified, filters to builds that finished/started/queued after this date based on the queryOrder specified.
 
    .PARAMETER BuildNumber
 
    If specified, filters to builds that match this build number. Append * to do a prefix search.
 
    .PARAMETER Queues
 
    A comma-delimited list of queue IDs. If specified, filters to builds that ran against these queues.
 
    .PARAMETER Definitions
 
    A comma-delimited list of definition IDs. If specified, filters to builds for these definitions.
 
    .PARAMETER RepositoryType
     
    If specified, filters to builds that built from repositories of this type.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns AP build list for 'myFirstProject'
 
    Get-APBuildList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/builds/list?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $RepositoryId,

        [Parameter()]
        [int[]]
        $BuildIds,

        [Parameter()]
        [string]
        $BranchName,

        [Parameter()]
        [string]
        [ValidateSet('finishTimeAscending', 'finishTimeDescending', 'queueTimeAscending', 'queueTimeDescending', 'startTimeAscending', 'startTimeDescending')]
        $QueryOrder,

        [Parameter()]
        [ValidateSet('excludeDeleted', 'includeDeleted', 'onlyDeleted')]
        [string]
        $DeletedFilter,   
        
        [Parameter()]
        [int]
        $MaxBuildsPerDefinition,

        [Parameter()]
        [string]
        $ContinuationToken,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [string[]]
        $Properties,

        [Parameter()]
        [string[]]
        $TagFilters,

        [Parameter()]
        [ValidateSet('canceled', 'failed', 'none', 'partiallySucceeded', 'succeeded')]
        [string]
        $ResultFilter,

        [Parameter()]
        [ValidateSet('all', 'cancelling', 'completed', 'inProgress', 'none', 'notStarted', 'postponed')]
        [string]
        $StatusFilter,

        [Parameter()]
        [ValidateSet('all', 'batchedCI', 'buildCompletion', 'checkInShelveset', 'individualCI', 'manual', 'none', 'pullRequest', 'schedule', 'triggered', 'userCreated', 'validateShelveset')]
        [string]
        $ReasonFilter,

        [Parameter()]
        [string]
        $RequestedFor,

        [Parameter()]
        [datetime]
        $MaxTime,

        [Parameter()]
        [datetime]
        $MinTime,

        [Parameter()]
        [string]
        $BuildNumber,

        [Parameter()]
        [int[]]
        $Queues,

        [Parameter()]
        [int[]]
        $Definitions,

        [Parameter()]
        [string]
        $RepositoryType
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'build-builds'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APDashboardList.ps1
function Get-APDashboardList
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline dashboard from a project.
 
    .DESCRIPTION
 
    Returns Azure Pipeline dashboard from a project.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines dashboard(s).
 
    .EXAMPLE
 
    Tetruns a list of Azure Pipelines dashboards for 'myFirstProject'
 
    Get-APDashboardList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/dashboard/dashboards/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'dashboard-dashboards'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APDeletedRepository.ps1
function Get-APDeletedRepository
{
    <#
    .SYNOPSIS
 
    Returns a deleted git repository.
 
    .DESCRIPTION
 
    Returns a deleted git repository based a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines git repository.
 
    .EXAMPLE
 
    Returns a list of deleted git repositories.
 
    Get-APDeletedRepository -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/get%20deleted%20repositories?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'git-deletedrepositories'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APDeploymentGroup.ps1
function Get-APDeploymentGroup
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline deployment group.
 
    .DESCRIPTION
 
    Returns Azure Pipeline deployment group by deployment group id.
    The deployment group id can be retrieved by using Get-APDeploymentGroupList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DeploymentGroupId
 
    ID of the deployment group.
 
    .PARAMETER ActionFilter
 
    Get the deployment group only if this action can be performed on it.
 
    .PARAMETER Expand
 
    Include these additional details in the returned objects.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines deployment group.
 
    .EXAMPLE
 
    Returns AP deployment group with the deployment group id of '6' for 'myFirstProject'.
 
    Get-APDeploymentGroup -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DeploymentGroupID 6
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/deploymentgroups/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $DeploymentGroupID,

        [Parameter()]
        [ValidateSet('manage', 'none', 'use')]
        [string]
        $ActionFilter,

        [Parameter()]
        [ValidateSet('machines', 'none', 'tags')]
        [string]
        $Expand
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-deploymentGroupId') -f $DeploymentGroupID
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken    
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential    
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APDeploymentGroupList.ps1
function Get-APDeploymentGroupList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline deployment groups.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline deployment groups based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
 
    Name of the deployment group.
 
    .PARAMETER ActionFilter
 
    Get the deployment group only if this action can be performed on it.
 
    .PARAMETER Expand
 
    Include these additional details in the returned objects.
 
    .PARAMETER ContinuationToken
 
    Get deployment groups with names greater than this continuationToken lexicographically.
 
    .PARAMETER Top
 
    Maximum number of deployment groups to return. Default is 1000.
 
    .PARAMETER Ids
 
    Comma separated list of IDs of the deployment groups.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines deployment group.
 
    .EXAMPLE
 
    Returns AP deployment group list for 'myFirstProject'.
 
    Get-APDeploymentGroupList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .EXAMPLE
 
    Returns AP deployment group with the name 'Dev' for 'myFirstProject'.
 
    Get-APDeploymentGroupList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -Name Dev
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/deploymentgroups/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $Name,

        [Parameter()]
        [ValidateSet('manage', 'none', 'use')]
        [string]
        $ActionFilter,

        [Parameter()]
        [ValidateSet('machines', 'none', 'tags')]
        [string]
        $Expand,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [int[]]
        $Ids
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'distributedtask-deploymentgroups'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APDeploymentList.ps1
function Get-APDeploymentList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline deployments.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline deployments based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER MaxStartedTime
     
    Deployments with max started time by will be returned.
 
    .PARAMETER MinStartedTime
 
    Deployments with min started time by will be returned.
 
    .PARAMETER CreatedFor
     
    Deployments with created for by will be returned.
 
    .PARAMETER ContinuationToken
     
    Gets the releases after the continuation token provided.
 
    .PARAMETER Top
     
    Number of deployments to return. Default is 50.
 
    .PARAMETER QueryOrder
     
    The order in which to return the query in.
 
    .PARAMETER LatestAttemptsOnly
 
    The latest attempt for stage will be returned.
 
    .PARAMETER OperationStatus
     
    Deployments with the operation status by will be returned.
 
    .PARAMETER DeploymentStatus
     
    Deployments with deployment status by will be returned.
 
    .PARAMETER MaxModifiedTime
     
    Deployments with max modified time by will be returned.
 
    .PARAMETER MinModifiedTime
     
    Deployments with min modified time by will be returned.
 
    .PARAMETER CreatedBy
 
    Deployments with given created by will be returned.
     
    .PARAMETER DefinitionEnvironmentId
     
    Undefined, see link for documentation
 
    .PARAMETER DefinitionId
     
    Deployments from this release definition Id.
 
    .PARAMETER SourceBranch
     
    Deployments with given source branch will be returned.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines release(s)
 
    .EXAMPLE
 
    Returns AP release list for 'myFirstProject'.
 
    Get-APDeploymentList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/release/releases/list?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter()]
        [string]
        $MaxStartedTime,

        [Parameter()]
        [string]
        $MinStartedTime,

        [Parameter()]
        [string]
        $CreatedFor,

        [Parameter()]
        [int]
        $ContinuationToken,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [string]
        [ValidateSet('ascending', 'descending')]
        $QueryOrder,

        [Parameter()]
        [bool]
        $LatestAttemptsOnly,

        [Parameter()]
        [ValidateSet('all', 'approved', 'canceled', 'deferred', 'gateFailed', 'manualInterventionPending', 'pending', 'phaseCanceled', 'phaseFailed', 'phaseInProgress', 'phasePartiallySucceeded', 'phasedSucceeded', 'queued', 'queuedForAgent', 'queuedForPipeline', 'rejected', 'scheduled', 'undefined')]
        [string]
        $OperationStatus,

        [Parameter()]
        [ValidateSet('all', 'failed', 'inProgress', 'notDeployed', 'partiallySucceeded', 'succeeded', 'undefined')]
        [string]
        $DeploymentStatus,

        [Parameter()]
        [string]
        $MaxModifiedTime,

        [Parameter()]
        [string]
        $MinModifiedTime,

        [Parameter()]
        [string]
        $CreatedBy,

        [Parameter()]
        [int]
        $DefinitionEnvironmentId,

        [Parameter()]
        [int]
        $DefinitionId,

        [Parameter()]
        [string]
        $SourceBranch
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'release-deployments'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APFeed.ps1
function Get-APFeed
{
    <#
    .SYNOPSIS
 
    Returns aa Azure Pipeline feed.
 
    .DESCRIPTION
 
    Returns an Azure Pipeline feed by feed id.
    The feed id can be retrieved by using Get-APFeedList.
    The feed id can be either the feed name or its guid id.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedId
 
    Name or Id of the feed.
 
    .PARAMETER IncludeDeletedUpstreams
 
    Include upstreams that have been deleted in the response.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines feed
 
    .EXAMPLE
 
    Returns the AP feed with the feed id of 'myFeed'.
 
    Get-APFeed -Instance 'https://dev.azure.com' -Collection 'myCollection' -FeedId 'myFeed'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/feed%20%20management/get%20feed?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $FeedId,

        [Parameter()]
        [bool]
        $IncludeDeletedUpstreams
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'feed-feedId') -f $FeedId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APFeedList.ps1
function Get-APFeedList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline feeds.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipelin feeds based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedRole
 
    Filter by this role, either Administrator(4), Contributor(3), or Reader(2) level permissions.
 
    .PARAMETER IncludeDeletedUpstreams
 
    Include upstreams that have been deleted in the response.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines feed(s)
 
    .EXAMPLE
 
    Returns AP feed list for 'myCollection'
 
    Get-APFeedList -Instance 'https://dev.azure.com' -Collection 'myCollection'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/feed%20%20management/get%20feeds?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [ValidateSet('administrator', 'collaborator', 'contributor', 'reader')]
        [string]
        $FeedRole,

        [Parameter()]
        [bool]
        $IncludeDeletedUpstreams
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'feed-feeds'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APGitItem.ps1
function Get-APGitItem
{
    <#
    .SYNOPSIS
 
    Returns item metadata and/or content for a single item.
 
    .DESCRIPTION
 
    Returns item metadata and/or content for a single item by repository id.
    The id can be retrieved by using Get-APRepository.
    The download parameter is to indicate whether the content should be available as a download or just sent as a stream in the response. Doesn't apply to zipped content, which is always returned as a download.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER RepositoryId
 
    The id of the repository.
 
    .PARAMETER Path
 
    The item path.
 
    .PARAMETER ScopePath
 
    The path scope, defaults to null.
 
    .PARAMETER RecursionLevel
 
    The recursion level of this request, defaults to none.
 
    .PARAMETER IncludeContentMetadata
 
    Set to true to include content metadata, defaults to false.
 
    .PARAMETER LatestProcessedChange
 
    Set to true to include the latest changes, defaults to false.
 
    .PARAMETER Download
 
    Set to true to download the response as a file, defaults to false.
 
    .PARAMETER Format
 
    If specified, this overrides the HTTP Accept request header to return either 'json' or 'zip'. If $format is specified, then api-version should also be specified as a query parameter.
 
    .PARAMETER IncludeContent
 
    Set to true to include item content when requesting json, defaults to false.
 
    .PARAMETER ResolveLfs
 
    Set to true to resolve Git LFS pointer files to return actual content from Git LFS. Default is false.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, git item metadata
 
    .EXAMPLE
 
    Returns the root of the repository with the name of 'myRepository'.
 
    $session = Get-APSession -SessionName 'mySession'
    $repository = Get-APRepositoryList -Session $session | ? name -eq 'myRepository'
    $getAPGitItemSplat = @{
        RepositoryId = $repository.Id
        Session = $session
    }
    Get-APGitItem @getAPGitItemSplat
 
    .EXAMPLE
 
    Returns all files and folders at the path of 'src/My.Project/myContacts' by using 'full' recursion.
 
    $session = Get-APSession -SessionName 'mySession'
    $repository = Get-APRepositoryList -Session $session | ? name -eq 'myRepository'
    $getAPGitItemSplat = @{
        ScopePath = 'src/My.Project/myContacts'
        RecursionLevel = 'full'
        RepositoryId = $repository.Id
        Session = $session
    }
    Get-APGitItem @getAPGitItemSplat
 
    .EXAMPLE
 
    Returns the content of the powershell script 'myDeployment.ps1'. Save the output of Get-APGitItem and pass it to Out-File to save the content to a file.
 
    $session = Get-APSession -SessionName 'mySession'
    $repository = Get-APRepositoryList -Session $session | ? name -eq 'myRepository'
    $getAPGitItemSplat = @{
        ScopePath = 'src/Deployment/myDeployment.ps1'
        RepositoryId = $repository.Id
        Session = $session
    }
    Get-APGitItem @getAPGitItemSplat
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/items/get?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $RepositoryId, 

        [Parameter()]
        [string]
        $Path,

        [Parameter()]
        [string]
        $ScopePath,

        [Parameter()]
        [ValidateSet('full', 'none', 'oneLevel', 'oneLevelPlusNestedEmptyFolders')]
        [string]
        $RecursionLevel, 

        [Parameter()]
        [bool]
        $IncludeContentMetadata, 

        [Parameter()]
        [bool]
        $LatestProcessedChange,

        [Parameter()]
        [bool]
        $Download,

        [Parameter()]
        [string]
        $Format,

        [Parameter()]
        [bool]
        $IncludeContent,

        [Parameter()]
        [bool]
        $ResolveLfs
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'git-items') -f $RepositoryId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APGitPullRequestList.ps1
function Get-APGitPullRequestList
{
    <#
    .SYNOPSIS
 
    Returns a list of pull requests.
 
    .DESCRIPTION
 
    Returns a list of pull requests matching a specified criteria..
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specify a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
   .PARAMETER RepositoryId
 
    The repository ID of the pull request's target branch.
 
    .PARAMETER SearchCriteria_IncludeLinks
 
    Whether to include the _links field on the shallow references.
 
    .PARAMETER SearchCriteria_SourceRefName
 
    If set, search for pull requests from this branch.
 
    .PARAMETER SearchCriteria_SourceRepositoryId
 
    If set, search for pull requests whose source branch is in this repository.
 
    .PARAMETER SearchCriteria_TargetRefName
 
    If set, search for pull requests into this branch.
 
    .PARAMETER SearchCriteria_Status
 
    If set, search for pull requests that are in this state. Defaults to Active if unset.
    Acceptable values are (as of API version 5.1):
        abandoned : Pull request is abandoned.
        active : Pull request is active.
        all : Used in pull request search criterias to include all statuses.
        completed : Pull request is completed.
        notSet : Status not set. Default state.
 
    .PARAMETER SearchCriteria_ReviewerId
 
    If set, search for pull requests that have this identity as a reviewer.
 
    .PARAMETER SearchCriteria_CreatorId
 
    If set, search for pull requests that were created by this identity.
 
    .PARAMETER SearchCriteria_RepositoryId
 
    If set, search for pull requests whose target branch is in this repository.
 
    .PARAMETER Skip
 
    The number of pull requests to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
 
    .PARAMETER Top
 
    The maximum number of pull requests to return.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, pull requests
 
    .EXAMPLE
 
    Returns all active pull requests for repositoryId 'e0eb12ee-83f2-4446-ac51-d067949e3a78'
 
    Get-APGitPullRequestList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -RepositoryId 'e0eb12ee-83f2-4446-ac51-d067949e3a78'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/get%20pull%20requests?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [string]
        $RepositoryId,

        [Parameter()]
        [boolean]
        $SearchCriteria_IncludeLinks,

        [Parameter()]
        [string]
        $SearchCriteria_SourceRefName,

        [Parameter()]
        [string]
        $SearchCriteria_SourceRepositoryId,

        [Parameter()]
        [string]
        $SearchCriteria_TargetRefName,

        [Parameter()]
        [string]
        [ValidateSet('abandoned', 'active', 'all', 'completed', 'notSet')]
        $SearchCriteria_Status,

        [Parameter()]
        [string]
        $SearchCriteria_ReviewerId,

        [Parameter()]
        [string]
        $SearchCriteria_CreatorId,

        [Parameter()]
        [string]
        $SearchCriteria_RepositoryId,

        [Parameter()]
        [int]
        $Skip,

        [Parameter()]
        [int]
        $Top
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'git-pullRequests'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APGitRefList.ps1
function Get-APGitRefList
{
    <#
    .SYNOPSIS
 
    Queries the provided repository for its refs and returns them.
 
    .DESCRIPTION
 
    Queries the provided repository for its refs and returns them based on the repository id.
    The id can be retrieved by using Get-APRepositoryList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER RepositoryId
 
    The name or ID of the repository.
 
    .PARAMETER Filter
 
    [optional] A filter to apply to the refs (starts with).
 
    .PARAMETER IncludeLinks
 
    [optional] Specifies if referenceLinks should be included in the result. default is false.
 
    .PARAMETER IncludeStatuses
 
    [optional] Includes up to the first 1000 commit statuses for each ref. The default value is false.
 
    .PARAMETER IncludeMyBranches
 
    [optional] Includes only branches that the user owns, the branches the user favorites, and the default branch. The default value is false. Cannot be combined with the filter parameter.
 
    .PARAMETER LatestStatusesOnly
 
    [optional] True to include only the tip commit status for each ref. This option requires includeStatuses to be true. The default value is false.
 
    .PARAMETER PeelTags
 
    [optional] Annotated tags will populate the PeeledObjectId property. default is false.
 
    .PARAMETER FilterContains
 
    [optional] A filter to apply to the refs (contains).
 
    .PARAMETER Top
 
    [optional] Maximum number of refs to return. It cannot be bigger than 1000. If it is not provided but continuationToken is, top will default to 100.
 
    .PARAMETER ContinuationToken
 
    The continuation token used for pagination.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines ref(s).
 
    .EXAMPLE
 
    Returns all the refs for a repository named 'myRepository'.
 
    Get-APGitRefList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -RepositoryId 'myRepository'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/refs/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
        
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $RepositoryId,

        [Parameter()]
        [string]
        $Filter,

        [Parameter()]
        [bool]
        $IncludeLinks,

        [Parameter()]
        [bool]
        $IncludeStatuses,

        [Parameter()]
        [bool]
        $IncludeMyBranches,
        
        [Parameter()]
        [bool]
        $LatestStatusesOnly,

        [Parameter()]
        [bool]
        $PeelTags,

        [Parameter()]
        [string]
        $FilterContains,

        [Parameter()]
        [string]
        $Top,

        [Parameter()]
        [string]
        $ContinuationToken
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'git-refs') -f $RepositoryId        
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APGroup.ps1
function Get-APGroup
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipeline user account.
 
    .DESCRIPTION
 
    Returns Azure Pipeline user account by user descriptor.
    The descriptor can be retrieved by using Get-APGroupList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER GroupDescriptor
 
    The descriptor of the desired graph group.
 
    .INPUTS
     
    None, does not support the pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines account(s)
 
    .EXAMPLE
 
    Returns AP group with the group descriptor of 'aad.OWRjNmIjMtZjNjY3ZDQ0LWIzOTgtZmYyMTM4N2E3NGJj' for 'myCollection'.
 
    Get-APGroup -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiVersion 5.0-preview -GroupDescriptor 'aad.OWRjNmIjMtZjNjY3ZDQ0LWIzOTgtZmYyMTM4N2E3NGJj'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/groups/get?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $GroupDescriptor
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        If ($ApiVersion -notmatch '5.*')
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: Groups are not supported in api versions earlier the 5.0." -ErrorAction 'Stop'
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'graph-groupId') -f $GroupDescriptor
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APGroupEntitlementsList.ps1
function Get-APGroupEntitlementsList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline group entitlements.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline group entitlements based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .INPUTS
     
    None, does not support the pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines account(s)
 
    .EXAMPLE
 
    Returns the AP group entitlements list for 'myCollection'.
 
    Get-APGroupEntitlementsList -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiVersion 5.0-preview
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/memberentitlementmanagement/group%20entitlements/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        If ($ApiVersion -notmatch '5.*')
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: Groups are not supported in api versions earlier the 5.0." -ErrorAction 'Stop'
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'groupentitlements-entitlements'
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APGroupList.ps1
function Get-APGroupList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline group accounts.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline group accounts based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ScopeDescriptor
 
    Specify a non-default scope (collection, project) to search for groups.
 
    .PARAMETER SubjectTypes
 
    A comma separated list of user subject subtypes to reduce the retrieved results, e.g. Microsoft.IdentityModel.Claims.ClaimsIdentity
 
    .PARAMETER ContinuationToken
 
    An opaque data blob that allows the next page of data to resume immediately after where the previous page ended. The only reliable way to know if there is more data left is the presence of a continuation token.
 
    .INPUTS
     
    None, does not support the pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines account(s)
 
    .EXAMPLE
 
    Returns AP group list for 'myCollection'.
     
    Get-APGroupList -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiVersion 5.0-preview
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/groups/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $ScopeDescriptor,

        [Parameter()]
        [string[]]
        $SubjectTypes,

        [Parameter()]
        [string]
        $ContinuationToken
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        If ($ApiVersion -notmatch '5.*')
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: Groups are not supported in api versions earlier the 5.0." -ErrorAction 'Stop'
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'graph-groups'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APInstalledExtension.ps1
function Get-APInstalledExtension
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline installed extension.
 
    .DESCRIPTION
 
    Returns Azure Pipeline installed extension by name.
    The name can be retrieved by using Get-APInstalledExtensionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER PublisherName
 
    Name of the publisher. Example: "MDSolutions".
 
    .PARAMETER ExtensionName
     
    Name of the extension. Example: "WindowsServiceManager".
 
    .PARAMETER AssetTypes
     
    Undocumented.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines extension(s).
 
    .EXAMPLE
 
    Returns the WindowsServiceManager extension.
 
    Get-APInstalledExtension -Instance 'https://dev.azure.com' -Collection 'myCollection' -ExtensionName 'WindowsServiceManager'
 
    .LINK
 
    Windows Service Manager extension:
    https://marketplace.visualstudio.com/items?itemName=MDSolutions.WindowsServiceManagerWindowsServiceManager
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/extensionmanagement/installed%20extensions/get?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $PublisherName,

        [Parameter(Mandatory)]
        [string]
        $ExtensionName,

        [Parameter()]
        [string[]]
        $AssetTypes
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'extensionmanagement-installedextensionsbyname') -f $PublisherName, $ExtensionName
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APInstalledExtensionList.ps1
function Get-APInstalledExtensionList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline installed extensions.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline installed extensions based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER IncludeDisabledExtensions
 
    If true (the default), include disabled extensions in the results.
 
    .PARAMETER IncludeErrors
 
    If true, include installed extensions with errors.
 
    .PARAMETER AssetTypes
 
    Undocumented.
 
    .PARAMETER IncludeInstallationIssues
 
    Undocumented.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines installed extension(s).
 
    .EXAMPLE
 
    Returns AP installed extension list for 'myCollection'
 
    Get-APInstalledExtensionList -Instance 'https://dev.azure.com' -Collection 'myCollection'
 
    .LINK
 
    Windows Service Manager extension:
    https://marketplace.visualstudio.com/items?itemName=MDSolutions.WindowsServiceManagerWindowsServiceManager
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/extensionmanagement/installed%20extensions/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [bool]
        $IncludeDisabledExtensions,

        [Parameter()]
        [string[]]
        $AssetTypes,

        [Parameter()]
        [bool]
        $IncludeInstallationIssues
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'extensionmanagement-installedextensions'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APNotificationSubscription.ps1
function Get-APNotificationSubscription
{
    <#
    .SYNOPSIS
 
    Get a notification subscription by its id.
 
    .DESCRIPTION
 
    Get a notification subscription by its id.
    The id can be retrieved with Get-APSubscriptionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER SubscriptionId
 
    The id of the subscription.
 
    .PARAMETER QueryFlags
 
    Undocumented.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines subscription list.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/notification/subscriptions/get?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $SubscriptionId,

        [Parameter()]
        [string[]]
        $QueryFlags
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'notification-subscriptionId') -f $SubscriptionId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APNotificationSubscriptionList.ps1
function Get-APNotificationSubscriptionList
{
    <#
    .SYNOPSIS
 
    Get a list of notification subscriptions, either by subscription IDs or by all subscriptions for a given user or group.
 
    .DESCRIPTION
 
    Get a list of notification subscriptions, either by subscription IDs or by all subscriptions for a given user or group.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER TargetId
 
    User or group id.
 
    .PARAMETER Ids
 
    List of subscription ids.
 
    .PARAMETER QueryFlags
 
    Undocumented.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines subscription list.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/notification/subscriptions/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $TargetId,

        [Parameter()]
        [string[]]
        $Ids,

        [Parameter()]
        [string[]]
        $QueryFlags
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'notification-subscriptions'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APNotificationSubscriptionTemplateList.ps1
function Get-APNotificationSubscriptionTemplateList
{
    <#
    .SYNOPSIS
 
    Get available subscription templates.
 
    .DESCRIPTION
 
    Get available subscription templates.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines subscription list.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/notification/subscriptions/get%20subscription%20templates?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'notification-subscriptionTemplates'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPackage.ps1
function Get-APPackage
{
    <#
    .SYNOPSIS
 
    Returns an of Azure Pipeline package.
 
    .DESCRIPTION
 
    Returns an Azure Pipeline package by package id.
    The package id can be retrieved by using Get-APPackageList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedId
 
    Name or Id of the feed.
 
    .PARAMETER PackageId
 
    The package Id (GUID Id, not the package name).
 
    .PARAMETER IncludeAllVersions
 
    True to return all versions of the package in the response. Default is false (latest version only).
 
    .PARAMETER IncludeUrls
 
    True to return REST Urls with the response. Default is True.
 
    .PARAMETER IsListed
 
    Only applicable for NuGet packages, setting it for other package types will result in a 404. If false, delisted package versions will be returned. Use this to filter the response when includeAllVersions is set to true. Default is unset (do not return delisted packages).
 
    .PARAMETER IsRelease
 
    Only applicable for Nuget packages. Use this to filter the response when includeAllVersions is set to true. Default is True (only return packages without prerelease versioning).
 
    .PARAMETER IncludeDeleted
 
    Return deleted or unpublished versions of packages in the response. Default is False.
 
    .PARAMETER IncludeDescription
 
    Return the description for every version of each package in the response. Default is False.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines package
 
    .EXAMPLE
 
    Returns AP package with the feed id of 'myFeed' and the package id 'a9522a15-4318-4f82-9d87-ed926ddb5e12'.
 
    Get-APPackage -Instance 'https://dev.azure.com' -Collection 'myCollection' -FeedId 'myFeed' -PackageId 'a9522a15-4318-4f82-9d87-ed926ddb5e12'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/feed%20%20management/get%20feed?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $FeedId,

        [Parameter(Mandatory)]
        [string]
        $PackageId,

        [Parameter()]
        [bool]
        $IncludeAllVersions,

        [Parameter()]
        [bool]
        $IncludeUrls,

        [Parameter()]
        [bool]
        $IsListed,

        [Parameter()]
        [bool]
        $IsRelease,

        [Parameter()]
        [bool]
        $IncludeDeleted,

        [Parameter()]
        [bool]
        $IncludeDescription
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'feed-packageId') -f $FeedId, $PackageId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APPackageList.ps1
function Get-APPackageList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline packages.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipelin packages based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedId
 
    Name or Id of the feed.
 
    .PARAMETER IsCached
 
    [Obsolete] Used for legacy scenarios and may be removed in future versions.
 
    .PARAMETER IncludeDeleted
 
    Return deleted or unpublished versions of packages in the response. Default is False.
 
    .PARAMETER Skip
 
    Skip the first N packages (or package versions where getTopPackageVersions=true)
 
    .PARAMETER Top
 
    Get the top N packages (or package versions where getTopPackageVersions=true)
 
    .PARAMETER IncludeDescription
 
    Return the description for every version of each package in the response. Default is False.
 
    .PARAMETER IsRelease
 
    Only applicable for Nuget packages. Use this to filter the response when includeAllVersions is set to true. Default is True (only return packages without prerelease versioning).
     
    .PARAMETER GetTopPackageVersions
 
    Changes the behavior of $top and $skip to return all versions of each package up to $top. Must be used in conjunction with includeAllVersions=true
 
    .PARAMETER IsListed
 
    Only applicable for NuGet packages, setting it for other package types will result in a 404. If false, delisted package versions will be returned. Use this to filter the response when includeAllVersions is set to true. Default is unset (do not return delisted packages).
 
    .PARAMETER IncludeAllVersions
 
    True to return all versions of the package in the response. Default is false (latest version only).
 
    .PARAMETER IncludeUrls
 
    True to return REST Urls with the response. Default is True.
 
    .PARAMETER NormalizedPackageName
         
    [Obsolete] Used for legacy scenarios and may be removed in future versions.
 
    .PARAMETER PackageNameQuery
 
    Filter to packages that contain the provided string. Characters in the string must conform to the package name constraints.
 
    .PARAMETER ProtocolType
 
    One of the supported artifact package types.
 
    .PARAMETER DirectUpstreamId
 
    Filter results to return packages from a specific upstream.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines package(s)
 
    .EXAMPLE
 
    Returns AP package list with the feed id of 'myFeed'.
 
    Get-APPackageList -Instance 'https://dev.azure.com' -Collection 'myCollection' -FeedId 'myFeed'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/artifact%20%20details/get%20packages?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $FeedId,

        [Parameter()]
        [bool]
        $IsCached,
        
        [Parameter()]
        [bool]
        $IncludeDeleted,

        [Parameter()]
        [int]
        $Skip,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [bool]
        $IncludeDescription,
        
        [Parameter()]
        [bool]
        $IsRelease,

        [Parameter()]
        [bool]
        $GetTopPackageVersions,

        [Parameter()]
        [bool]
        $IsListed,

        [Parameter()]
        [bool]
        $IncludeAllVersions,

        [Parameter()]
        [bool]
        $IncludeUrls,

        [Parameter()]
        [string]
        $NormalizedPackageName,

        [Parameter()]
        [string]
        $PackageNameQuery,

        [Parameter()]
        [string]
        $ProtocolType,

        [Parameter()]
        [string]
        $DirectUpstreamId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'feed-packages') -f $FeedId 
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APPersonalAccessTokenList.ps1
function Get-APPersonalAccessTokenList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline builds.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline builds based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER SubjectDescriptor
 
    The descriptor of the target user.
 
    .PARAMETER PageSize
 
    The maximum number of results to return on each page.
 
    .PARAMETER ContinuationToken
 
    An opaque data blob that allows the next page of data to resume immediately after where the previous page ended. The only reliable way to know if there is more data left is the presence of a continuation token.
 
    .PARAMETER IsPublic
 
    Set to false for PAT tokens and true for SSH tokens.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns AP build list for 'myFirstProject'
 
    Get-APPersonalAccessTokenList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/builds/list?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $SubjectDescriptor,

        [Parameter()]
        [int]
        $PageSize,

        [Parameter()]
        [string]
        $ContinuationToken,

        [Parameter()]
        [bool]
        $IsPublic
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'tokenadmin-subjectDescriptor') -f $SubjectDescriptor
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyConfiguration.ps1
function Get-APPolicyConfiguration
{
    <#
    .SYNOPSIS
 
    Returns a Azure Pipeline policy configuration.
 
    .DESCRIPTION
 
    Returns a Azure Pipeline policy configuration by configuration id.
    The id can be retrieved by using Get-APPolicyConfigurationList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ConfigurationId
     
    Id of the policy configuration.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy configuration(s)
 
    .EXAMPLE
 
    Returns policy configuration with the id of '7'.
 
    Get-APPolicyConfiguration -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ConfigurationId '7'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations/get?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [int]
        $ConfigurationId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-configurationId') -f $ConfigurationId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyConfigurationList.ps1
function Get-APPolicyConfigurationList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline policy configurations.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline policy configurations based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Scope
     
    [Provided for legacy reasons] The scope on which a subset of policies is defined.
 
    .PARAMETER PolicyType
 
    Filter returned policies to only this type.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy configuration(s)
 
    .EXAMPLE
 
    Returns policy configuration list for 'myFirstProject'.
 
    Get-APPolicyConfigurationList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations/list?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $Scope,

        [Parameter()]
        [string]
        $PolicyType
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'policy-configurations'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyEvaluation.ps1
function Get-APPolicyEvaluation
{
    <#
    .SYNOPSIS
 
    Returns a Azure Pipeline policy evaluation.
 
    .DESCRIPTION
 
    Returns a Azure Pipeline policy evaluation by evaluation id.
    The id can be retrieved by using Get-APPolicyEvaluationList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER EvaluationId
     
    Id of the policy evaluation.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy evaluation(s)
 
    .EXAMPLE
 
    Returns policy evaluation with the id of '7'.
 
    Get-APPolicyEvaluation -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -EvaluationId '7'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/evaluations/get?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $EvaluationId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-evaluationId') -f $EvaluationId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyEvaluationList.ps1
function Get-APPolicyEvaluationList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline policy evaluations.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline policy evaluations based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ArtifactId
     
    A string which uniquely identifies the target of a policy evaluation.
 
    .PARAMETER IncludeNotApplicable
 
    Some policies might determine that they do not apply to a specific pull request. Setting this parameter to true will return evaluation records even for policies which don't apply to this pull request.
 
    .PARAMETER Top
 
    The number of policy evaluation records to retrieve.
 
    .PARAMETER Skip
 
    The number of policy evaluation records to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy evaluation(s)
 
    .EXAMPLE
 
    Returns policy evaluation list for 'myFirstProject'.
 
    Get-APPolicyEvaluationList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/evaluations/list?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $ArtifactId,

        [Parameter()]
        [switch]
        $IncludeNotApplicable,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [int]
        $Skip
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-evaluations') -f $ArtifactId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyRevision.ps1
function Get-APPolicyRevision
{
    <#
    .SYNOPSIS
 
    Returns a Azure Pipeline policy revision.
 
    .DESCRIPTION
 
    Returns a Azure Pipeline policy revision by revision id.
    The id can be retrieved by using Get-APPolicyRevisionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ConfigurationId
     
    The policy configuration id.
 
    .PARAMETER RevisionId
     
    Id of the policy revision.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy revision(s)
 
    .EXAMPLE
 
    Returns policy revision with the id of '7'.
 
    Get-APPolicyRevision -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -RevisionId '7'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/revisions/get?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $ConfigurationId,

        [Parameter(Mandatory)]
        [int]
        $RevisionId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-revisionId') -f $RevisionId, $ConfigurationId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyRevisionList.ps1
function Get-APPolicyRevisionList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline policy revisions.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline policy revisions based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ConfigurationId
     
    The policy configuration id.
 
    .PARAMETER Top
 
    The number of revisions to retrieve
 
    .PARAMETER Skip
 
    The number of revisions to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy revision(s)
 
    .EXAMPLE
 
    Returns policy revision list for 'myFirstProject'.
 
    Get-APPolicyRevisionList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/revisions/list?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $ConfigurationId,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [int]
        $Skip
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-revisions') -f $ConfigurationId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyType.ps1
function Get-APPolicyType
{
    <#
    .SYNOPSIS
 
    Returns a Azure Pipeline policy type.
 
    .DESCRIPTION
 
    Returns a Azure Pipeline policy type by type id.
    The id can be retrieved by using Get-APPolicyTypeList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER TypeId
     
    Id of the policy type.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy type(s)
 
    .EXAMPLE
 
    Returns policy type with the id of '7'.
 
    Get-APPolicyType -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -TypeId '7'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/types/get?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $TypeId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-typeId') -f $TypeId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APPolicyTypeList.ps1
function Get-APPolicyTypeList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline policy types.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline policy types based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy type(s)
 
    .EXAMPLE
 
    Returns policy type list for 'myFirstProject'.
 
    Get-APPolicyTypeList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/types/list?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'policy-types'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APProjectList.ps1
function Get-APProjectList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline build projects.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline build projects based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ContinuationToken
 
    A continuation token, returned by a previous call to this method, that can be used to return the next set of definitions.
 
    .PARAMETER Top
 
    The maximum number of definitions to return.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns AP project list for 'myFirstProject'.
 
    Get-APProjectList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/core/projects/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $ContinuationToken,

        [Parameter()]
        [int]
        $Top
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'project-projects'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APQueue.ps1
Function Get-APQueue
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipeline queue.
 
    .DESCRIPTION
 
    Returns an Azure Pipeline queue based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER QueueName
 
    Filters queues whose names start with this prefix.
 
    .PARAMETER ActionFilter
 
    Filter Queues based on the permission mentioned.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines queue(s)
 
    .EXAMPLE
 
    Returns AP queue list for 'myFirstProject'.
 
    Get-APQueue -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .EXAMPLE
 
    Returns AP queue with queue name of 'myQueue'.
 
    Get-APQueue -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -QueueName 'myQueue'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $QueueName,

        [Parameter()]
        [ValidateSet('none', 'manage', 'use')]
        [string]
        $ActionFilter
    )
    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'distributedtask-queues'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APRecycleBinRepository.ps1
function Get-APRecycleBinRepository
{
    <#
    .SYNOPSIS
 
    Returns a deleted git repository.
 
    .DESCRIPTION
 
    Returns a deleted git repository based a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines git repository.
 
    .EXAMPLE
 
    Returns a list of deleted git repositories.
 
    Get-APRecycleBinRepository -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/get%20deleted%20repositories?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'git-recycleBin'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APRelease.ps1
function Get-APRelease
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline release.
 
    .DESCRIPTION
 
    Returns Azure Pipeline release by release id.
    The id can be retrieved by using Get-APReleaseList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ReleaseId
     
    Id of the release.
 
    .PARAMETER ApprovalFilters
     
    A filter which would allow fetching approval steps selectively based on whether it is automated, or manual. This would also decide whether we should fetch pre and post approval snapshots. Assumes All by default.
 
    .PARAMETER PropertyFilters
     
    A comma-delimited list of extended properties to be retrieved. If set, the returned Release will contain values for the specified property Ids (if they exist). If not set, properties will not be included.
 
    .PARAMETER Expand
     
    A property that should be expanded in the release.
 
    .PARAMETER TopGateRecords
     
    Number of release gate records to get. Default is 5.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines release(s)
 
    .EXAMPLE
 
    Returns AP release with the release id of 7.
 
    Get-APRelease -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 7
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/get%20release?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $ReleaseId,

        [Parameter()]
        [string]
        $ApprovalFilters,

        [Parameter()]
        [string]
        $PropertyFilters,

        [Parameter()]
        [string]
        [ValidateSet('none', 'tasks')]
        $Expand,

        [Parameter()]
        [int]
        $TopGateRecords
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
  
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-releaseId') -f $ReleaseId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APReleaseDefinition.ps1
function Get-APReleaseDefinition
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipeline release definition.
 
    .DESCRIPTION
 
    Returns an Azure Pipeline release definition by definition id.
    The id can be retrieved by using Get-APReleaseDefinitionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER DefinitionId
     
    Releases with names starting with searchText.
 
    .PARAMETER PropertyFilters
     
    The property that should be expanded in the list of releases.
 
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines release definition(s).
 
    .EXAMPLE
 
    Returns the AP release definition with the definition id of '5'.
 
    Get-APReleaseDefinition -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DefinitionId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/definitions/get?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $DefinitionId,

        [Parameter()]
        [string[]]
        $PropertyFilters
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-definitionId') -f $DefinitionId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APReleaseDefinitionList.ps1
function Get-APReleaseDefinitionList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline release definitions.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline release definitions based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER SearchText
     
    Releases with names starting with searchText.
 
    .PARAMETER Expand
     
    The property that should be expanded in the list of releases.
 
    .PARAMETER ArtifactType
     
    Release definitions with given artifactType will be returned. Values can be Build, Jenkins, GitHub, Nuget, Team Build (external), ExternalTFSBuild, Git, TFVC, ExternalTfsXamlBuild.
 
    .PARAMETER Top
     
    Number of releases to get. Default is 50.
 
    .PARAMETER ContinuationToken
     
    Gets the releases after the continuation token provided.
 
    .PARAMETER QueryOrder
     
    Gets the results in the defined order of created date for releases. Default is descending.
 
    .PARAMETER Path
     
    Gets the release definitions under the specified path.
     
    .PARAMETER IsExactNameMatch
     
    Set to 'true' to get the release definitions with exact match as specified in searchText. Default is 'false'.
 
    .PARAMETER TagFilter
     
    A comma-delimited list of tags. Only releases with these tags will be returned.
 
    .PARAMETER PropertyFilters
     
    A comma-delimited list of extended properties to retrieve.
 
    .PARAMETER DefinitionIdFilter
     
    A comma-delimited list of release definitions to retrieve.
 
    .PARAMETER IsDeleted
     
    Gets the soft deleted releases, if true.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines release definition(s)
 
    .EXAMPLE
 
    Returns AP release definition list for 'myFirstProject'.
 
    Get-APReleaseDefinitionList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/definitions/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $SearchText,

        [Parameter()]
        [string]
        [ValidateSet('approvals', 'artifacts', 'environments', 'manualInterventions', 'none', 'tags', 'variables')]
        $Expand,

        [Parameter()]
        [string]
        $ArtifactType,

        [Parameter()]
        [string]
        $Top,

        [Parameter()]
        [string]
        $ContinuationToken,

        [Parameter()]
        [string]
        $QueryOrder,

        [Parameter()]
        [string]
        $Path,

        [Parameter()]
        [string]
        $IsExactNameMatch,

        [Parameter()]
        [string]
        $TagFilter,

        [Parameter()]
        [string]
        $PropertyFilters,

        [Parameter()]
        [string]
        $DefinitionIdFilter,

        [Parameter()]
        [bool]
        $IsDeleted
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'release-definitions'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APReleaseList.ps1
function Get-APReleaseList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline releases.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline releases based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER PropertyFilters
     
    A comma-delimited list of extended properties to retrieve.
 
    .PARAMETER TagFilter
     
    A comma-delimited list of tags. Only releases with these tags will be returned.
 
    .PARAMETER IsDeleted
     
    Gets the soft deleted releases, if true.
 
    .PARAMETER SourceBranchFilter
     
    Releases with given sourceBranchFilter will be returned.
 
    .PARAMETER ArtifactVersionId
     
    Releases with given artifactVersionId will be returned. E.g. in case of Build artifactType, it is buildId.
 
    .PARAMETER SourceId
     
    Unique identifier of the artifact used. e.g. For build it would be {projectGuid}:{BuildDefinitionId}, for Jenkins it would be {JenkinsConnectionId}:{JenkinsDefinitionId}, for TfsOnPrem it would be {TfsOnPremConnectionId}:{ProjectName}:{TfsOnPremDefinitionId}. For third-party artifacts e.g. TeamCity, BitBucket you may refer 'uniqueSourceIdentifier' inside vss-extension.json https://github.com/Microsoft/vsts-rm-extensions/blob/master/Extensions.
 
    .PARAMETER ArtifactTypeId
     
    Releases with given artifactTypeId will be returned. Values can be Build, Jenkins, GitHub, Nuget, Team Build (external), ExternalTFSBuild, Git, TFVC, ExternalTfsXamlBuild.
 
    .PARAMETER Expand
     
    The property that should be expanded in the list of releases.
 
    .PARAMETER ContinuationToken
     
    Gets the releases after the continuation token provided.
 
    .PARAMETER Top
     
    Number of releases to get. Default is 50.
 
    .PARAMETER QueryOrder
     
    Gets the results in the defined order of created date for releases. Default is descending.
 
    .PARAMETER MaxCreatedTime
 
    Releases that were created before this time.
 
    .PARAMETER MinCreatedTime
     
    Releases that were created after this time.
 
    .PARAMETER EnvironmentStatusFilter
     
    Integer value for the status filters are below.
    Undefined = 0,
    NotStarted = 1,
    InProgress = 2,
    Succeeded = 4,
    Canceled = 8,
    Rejected = 16,
    Queued = 32,
    Scheduled = 64,
    PartiallySucceeded = 128
    Environment Status - https://raw.githubusercontent.com/microsoft/vss-web-extension-sdk/master/typings/rmo.d.ts
 
    .PARAMETER StatusFilter
     
    Releases that have this status.
 
    .PARAMETER CreatedBy
     
    Releases created by this user.
 
    .PARAMETER SearchText
     
    Releases with names starting with searchText.
 
    .PARAMETER DefinitionEnvironmentId
     
    Undefined, see link for documentation
 
    .PARAMETER DefinitionId
     
    Releases from this release definition Id.
 
    .PARAMETER ReleaseIdFilter
     
    A comma-delimited list of releases Ids. Only releases with these Ids will be returned.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines release(s)
 
    .EXAMPLE
 
    Returns AP release list for 'myFirstProject'.
 
    Get-APReleaseList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/release/releases/list?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter()]
        [string]
        $PropertyFilters,

        [Parameter()]
        [string]
        $TagFilter,

        [Parameter()]
        [bool]
        $IsDeleted,

        [Parameter()]
        [string]
        $SourceBranchFilter,

        [Parameter()]
        [string]
        $ArtifactVersionId,

        [Parameter()]
        [string]
        $SourceId,

        [Parameter()]
        [string]
        $ArtifactTypeId,

        [Parameter()]
        [string]
        [ValidateSet('approvals', 'artifacts', 'environments', 'manualInterventions', 'none', 'tags', 'variables')]
        $Expand,

        [Parameter()]
        [int]
        $ContinuationToken,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [string]
        [ValidateSet('ascending', 'descending')]
        $QueryOrder,

        [Parameter()]
        [datetime]
        $MaxCreatedTime,

        [Parameter()]
        [datetime]
        $MinCreatedTime,

        [Parameter()]
        [string]
        $EnvironmentStatusFilter,

        [Parameter()]
        [string]
        [ValidateSet('abandoned', 'active', 'draft', 'undefined')]
        $StatusFilter,

        [Parameter()]
        [string]
        $CreatedBy,

        [Parameter()]
        [string]
        $SearchText,

        [Parameter()]
        [int]
        $DefinitionEnvironmentId,

        [Parameter()]
        [int]
        $DefinitionId,

        [Parameter()]
        [int]
        $ReleaseIdFilter
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'release-releases'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APReleaseTaskLog.ps1
function Get-APReleaseTaskLog
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline task log.
 
    .DESCRIPTION
 
    Returns Azure Pipeline release task log by the release id and environment id.
    The id can be retrieved by using Get-APReleaseList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ReleaseId
 
    The Id of the release.
 
    .PARAMETER EnvironmentId
 
    The Id of the release environment.
 
    .PARAMETER DeployPhaseId
 
    The Id of the release environment deploy phase.
 
    .PARAMETER TaskId
 
    The Id of the release environment task.
 
    .PARAMETER StartLine
 
    Starting line number for the logs.
 
    .PARAMETER EndLine
 
    Ending line numbers for the logs.
     
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    String, Azure Pipelines release task log(s).
 
    .EXAMPLE
 
    Returns the build with the id of '7' for the 'myFirstProject.
 
    Get-TaskLog -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 7 -EnvironmentId 8 -TaskId 9
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/builds/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
        
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $ReleaseId,

        [Parameter(Mandatory)]
        [int]
        $EnvironmentId,

        [Parameter(Mandatory)]
        [int]
        $DeployPhaseId,

        [Parameter(Mandatory)]
        [int]
        $TaskId,

        [Parameter()]
        [int]
        $StartLine,

        [Parameter()]
        [int]
        $EndLine
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-logs') -f $ReleaseId, $EnvironmentId, $DeployPhaseId, $TaskId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APRepository.ps1
function Get-APRepository
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipeline repository.
 
    .DESCRIPTION
 
    Returns an Azure Pipeline repository by repository id.
    The id can be retrieved by using Get-APRepositoryList.
    The id can be the guid or the name of the repository.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER RepositoryId
 
    The name or ID of the repository.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns AP repository with the repository id of 'myRepository'.
 
    Get-APRepository -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -RepositoryId 'myRepository'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/git/repositories/get%20repository?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $RepositoryId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'git-repositoryId') -f $RepositoryId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APRepositoryList.ps1
function Get-APRepositoryList
{
    <#
    .SYNOPSIS
 
    Returns a list Azure Pipeline repositories.
 
    .DESCRIPTION
 
    Returns a list Azure Pipeline repositories.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER IncludeLinks
 
    [optional] True to include reference links. The default value is false.
 
    .PARAMETER IncludeAllUrls
 
    [optional] True to include all remote URLs. The default value is false.
 
    .PARAMETER IncludeHidden
 
    [optional] True to include hidden repositories. The default value is false.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns AP repository list for 'myFirstProject'.
 
    Get-APRepositoryList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/git/repositories/list?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [bool]
        $IncludeLinks,

        [Parameter()]
        [bool]
        $IncludeAllUrls,

        [Parameter()]
        [bool]
        $IncludeHidden
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'git-repositories'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APSecurityNamespaceList.ps1
function Get-APSecurityNamespaceList
{
    <#
    .SYNOPSIS
 
    Returns a list of security namespaces.
 
    .DESCRIPTION
 
    Returns a list of security namespaces based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER SecurityNamespaceId
 
    Security namespace identifier.
 
    .PARAMETER LocalOnly
 
    If true, retrieve local security namespaces.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines security namespace(s)
 
    .EXAMPLE
 
    Returns all security namespaces
 
    Get-APBuildList -Session 'mySession'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/security/security%20namespaces/query?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $SecurityNamespaceId,

        [Parameter()]
        [bool]
        $LocalOnly
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'securitynamespaces-securityNamespaceId') -f $SecurityNamespaceId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APServiceEndpoint.ps1
function Get-APServiceEndpoint
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipelines service endpoint details.
 
    .DESCRIPTION
 
    Returns an Azure Pipelines service endpoint details based on a the endpoint id.
    The id can be retrieved by using Get-APServiceEndpointList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER EndpointId
 
    Id of the service endpoint.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines service endpoint execution record(s)
 
    .EXAMPLE
 
    Returns a service endpoint execution records for a service endpoint with the id of '7'.
 
    Get-APServiceEndpoint -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -EndpointId '7'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/get?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,
    
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,
    
        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
    
        [Parameter()]
        [string]
        $EndpointId
    )
    
    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'serviceendpoint-endpointId') -f $EndpointId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
        
    end
    {
    }
}
# Get-APServiceEndpointExecutionHistoryList.ps1
function Get-APServiceEndpointExecutionHistoryList
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipelines service endpoint execution records.
 
    .DESCRIPTION
 
    Returns an Azure Pipelinesservice endpoint execution records based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER EndpointId
 
    Id of the service endpoint.
 
    .PARAMETER Top
 
    Number of service endpoint execution records to get.
 
    .PARAMETER ContinuationToken
 
    A continuation token, returned by a previous call to this method, that can be used to return the next set of records
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines service endpoint execution record(s)
 
    .EXAMPLE
 
    Returns a service endpoint execution records for a service endpoint with the id of '7'.
 
    Get-APServiceEndpointExecutionHistoryList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -EndpointId '7'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/executionhistory/list?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,
    
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,
    
        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
    
        [Parameter()]
        [string]
        $EndpointId,
    
        [Parameter()]
        [string]
        $ContinuationToken,
    
        [Parameter()]
        [int]
        $Top
    )
    
    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'serviceendpoint-executionhistory') -f $EndpointId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
        
    end
    {
    }
}
# Get-APServiceEndpointList.ps1
function Get-APServiceEndpointList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline service endpoints.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline service endpoints based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER Type
 
    Type of the service endpoints.
 
    .PARAMETER AuthSchemes
 
    Authorization schemes used for service endpoints.
 
    .PARAMETER EndpointIds
 
    Ids of the service endpoints.
 
    .PARAMETER Owner
 
    Owner for service endpoints.
 
    .PARAMETER IncludeFailed
 
    Failed flag for service endpoints.
 
    .PARAMETER IncludeDetails
 
    Flag to include more details for service endpoints. This is for internal use only and the flag will be treated as false for all other requests
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines service endpoint(s)
 
    .EXAMPLE
 
    Returns AP service endpoint list for 'myFirstProject'
 
    Get-APServiceEndpointList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/get%20service%20endpoints?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $Type,

        [Parameter()]
        [string[]]
        $AuthSchemes,

        [Parameter()]
        [string[]]
        $EndpointIds,

        [Parameter()]
        [string]
        $Owner,
        
        [Parameter()]
        [bool]
        $IncludeFailed,
        
        [Parameter()]
        [bool]
        $IncludeDetails
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'serviceendpoint-endpoints'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APServiceEndpointName.ps1
function Get-APServiceEndpointName
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipelines service endpoint details.
 
    .DESCRIPTION
 
    Returns an Azure Pipelines service endpoint details based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
     
    .PARAMETER EndpointNames
 
    Names of the service endpoints.
 
    .PARAMETER Type
 
    Type of the service endpoints.
 
    .PARAMETER AuthSchemes
 
    Authorization schemes used for service endpoints.
 
    .PARAMETER Owner
 
    Owner for service endpoints.
 
    .PARAMETER IncludeFailed
 
    Failed flag for service endpoints.
 
    .PARAMETER IncludeDetails
 
    Flag to include more details for service endpoints. This is for internal use only and the flag will be treated as false for all other requests
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines service endpoint execution record(s)
 
    .EXAMPLE
 
    Returns a service endpoint execution records for a service endpoint with the name of 'myEndpoint'.
 
    Get-APServiceEndpointName -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -EndpointName 'myEndpoint'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/get%20service%20endpoints%20by%20names?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,
    
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,
    
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,
    
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,
    
        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string[]]
        $EndpointNames,

        [Parameter()]
        [string]
        $Type,

        [Parameter()]
        [string[]]
        $AuthSchemes,

        [Parameter()]
        [string]
        $Owner,
        
        [Parameter()]
        [bool]
        $IncludeFailed,
        
        [Parameter()]
        [bool]
        $IncludeDetails
    )
    
    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'serviceendpoint-endpoints') -f $EndpointName
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
        
    end
    {
    }
}
# Get-APServiceEndpointTypeList.ps1
function Get-APServiceEndpointTypeList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline service endpoint types.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline service endpoint types based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Type
 
    Type of service endpoint.
 
    .PARAMETER Scheme
 
    Scheme of service endpoint
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines service endpoint type(s)
 
    .EXAMPLE
 
    Returns service endpoint type list for 'myCollection'.
 
    Get-APServiceEndpointTypeList -Instance 'https://dev.azure.com' -Collection 'myCollection'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/types/list?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $Type,

        [Parameter()]
        [string]
        $Scheme
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'serviceendpoint-types'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APSession.ps1
Function Get-APSession
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipelines PS session data.
 
    .DESCRIPTION
 
    Returns Azure Pipelines PS session data that has been stored in the users local application data.
    Use Save-APSession to persist the session data to disk.
    The sensetive data is returned encrypted.
 
    .PARAMETER Id
     
    Session id.
 
    .PARAMETER SessionName
     
    The friendly name of the session.
 
    .PARAMETER Path
     
    The path where session data will be stored, defaults to $Script:ModuleDataPath.
 
    .LINK
 
    Save-APSession
    Remove-APSession
 
    .INPUTS
 
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject. Get-APSession returns a PSObject that contains the following:
        Instance
        Collection
        PersonalAccessToken
 
    .EXAMPLE
 
    Returns all AP sessions saved or in memory.
 
    Get-APSession
 
    .EXAMPLE
 
    Returns AP session with the session name of 'myFirstSession'.
 
    Get-APSession -SessionName 'myFirstSession'
 
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter(ValueFromPipeline,
            ValueFromPipelineByPropertyName)]
        [string]
        $SessionName,

        [Parameter(ParameterSetName = 'ById', 
            ValueFromPipeline,
            ValueFromPipelineByPropertyName)]
        [int]
        $Id,

        [Parameter()]
        [string]
        $Path = $Script:ModuleDataPath
    )
    Process
    {
        # Process memory sessions
        $_sessions = @()
        If ($null -ne $Global:_APSessions)
        {
            Foreach ($_memSession in $Global:_APSessions)
            {
                $_sessions += $_memSession
            }
        }
        
        # Process saved sessions
        If (Test-Path $Path)
        {
            $data = Get-Content -Path $Path -Raw | ConvertFrom-Json           
            Foreach ($_data in $data.SessionData)
            {
                $_object = New-Object -TypeName PSCustomObject -Property @{
                    Id          = $_data.Id
                    Instance    = $_data.Instance
                    Collection  = $_data.Collection
                    Project     = $_data.Project
                    SessionName = $_data.SessionName
                    Version     = $_data.Version
                    ApiVersion  = $_data.ApiVersion
                    Saved       = $_data.Saved
                }
                If ($_data.PersonalAccessToken)
                {
                    $_object | Add-Member -NotePropertyName 'PersonalAccessToken' -NotePropertyValue ($_data.PersonalAccessToken | ConvertTo-SecureString)
                }
                If ($_data.Credential)
                {
                    $_psCredentialObject = [pscredential]::new($_data.Credential.Username, ($_data.Credential.Password | ConvertTo-SecureString))
                    $_object | Add-Member -NotePropertyName 'Credential' -NotePropertyValue $_psCredentialObject
                }
                If ($_data.Proxy)
                {
                    $_object | Add-Member -NotePropertyName 'Proxy' -NotePropertyValue $_data.Proxy
                }
                If ($_data.ProxyCredential)
                {
                    $_psProxyCredentialObject = [pscredential]::new($_data.ProxyCredential.Username, ($_data.ProxyCredential.Password | ConvertTo-SecureString))
                    $_object | Add-Member -NotePropertyName 'ProxyCredential' -NotePropertyValue $_psProxyCredentialObject
                }
                $_sessions += $_object
            }
        }
        If ($PSCmdlet.ParameterSetName -eq 'ById')
        {
            $_sessions = $_sessions | Where-Object { $PSItem.Id -eq $Id }
        }
        If ($SessionName)
        {
            $_sessions = $_sessions | Where-Object { $PSItem.SessionName -eq $SessionName }
        }
        Return $_sessions
    }
}
# Get-APSourceProviderList.ps1
function Get-APSourceProviderList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline source providers.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline source providers based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines source provider(s)
 
    .EXAMPLE
 
    Returns AP spource provider list for 'myFirstProject'.
 
    Get-APSourceProviderList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/build/source%20providers/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'sourceProviders-sourceproviders'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APStorageKey.ps1
function Get-APStorageKey
{
    <#
    .SYNOPSIS
 
    Resolves a descriptor to a storage key.
 
    .DESCRIPTION
 
    Resolves a descriptor to a storage key by user subject descriptor.
    The descriptor can be retrieved by using Get-APGroupList or Get-APUserList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER SubjectDescriptor
 
    The descriptor of the desired user or group.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines account(s)
 
    .EXAMPLE
 
    Returns AP strorage key with the subject descriptor of 'aad.OWRjNmIjMtZjNjY3ZDQ0LWIzOTgtZmYyMTM4N2E3NGJj' for 'myCollection'.
 
    Get-APStorageKey -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiVersion 5.0-preview -SubjectDescriptor 'aad.OWRjNmIjMtZjNjY3ZDQ0LWIzOTgtZmYyMTM4N2E3NGJj'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/storage%20keys/get?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $SubjectDescriptor
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        If ($ApiVersion -notmatch '5.*')
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: User list is not supported in api versions earlier the 5.0." -ErrorAction 'Stop'
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'graph-storagekeys') -f $SubjectDescriptor
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APTarget.ps1
function Get-APTarget
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline deployment group target.
 
    .DESCRIPTION
 
    Returns Azure Pipeline deployment group target based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DeploymentGroupId
 
    ID of the deployment target to return.
 
    .PARAMETER TargetID
 
    ID of the deployment target to return.
 
    .PARAMETER Expand
 
    Include these additional details in the returned objects.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines deployment group.
 
    .EXAMPLE
 
    Returns AP targer witht the deployment group id of '6' and the target id of '25 for 'myFirstProject'.
 
    Get-APTarget -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DeploymentGroupID 6 -TargetId 25
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/targets/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [int]
        $DeploymentGroupID,

        [Parameter(Mandatory)]
        [int]
        $TargetId,

        [Parameter(ParameterSetName = 'ByQuery')]
        [ValidateSet('assignedRequest', 'capabilities', 'lastCompletedRequest', 'none')]
        [string]
        $Expand
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-targetId') -f $DeploymentGroupID, $TargetId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APTargetList.ps1
function Get-APTargetList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline deployment group targets.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline deployment group targets based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DeploymentGroupId
 
    ID of the deployment group.
 
    .PARAMETER Tags
 
    Get only the deployment targets that contain all these comma separted list of tags.
 
    .PARAMETER Name
 
    Name pattern of the deployment targets to return.
 
    .PARAMETER PartialNameMatch
 
    When set to true, treats name as pattern. Else treats it as absolute match. Default is false.
 
    .PARAMETER Expand
 
    Include these additional details in the returned objects.
     
    .PARAMETER AgentStatus
     
    Get only deployment targets that have this status.
     
    .PARAMETER AgentJobResult
 
    Get only deployment targets that have this last job result.
 
    .PARAMETER ContinuationToken
 
    Get deployment targets with names greater than this continuationToken lexicographically.
 
    .PARAMETER Top
 
    Maximum number of deployment targets to return. Default is 1000.
 
    .PARAMETER Enabled
 
    Get only deployment targets that are enabled or disabled. Default is 'null' which returns all the targets.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines deployment group.
 
    .EXAMPLE
 
    Returns AP target list with the deployment group id of '6 for 'myFirstProject'.
 
    Get-APTargetList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DeploymentGroupID 6
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/targets/list?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $DeploymentGroupID,

        [Parameter()]
        [string[]]
        $Tags,

        [Parameter()]
        [string]
        $Name,

        [Parameter()]
        [bool]
        $PartialNameMatch,

        [Parameter()]
        [ValidateSet('assignedRequest', 'capabilities', 'lastCompletedRequest', 'none')]
        [string]
        $Expand,
        
        [Parameter()]
        [ValidateSet('all', 'offline', 'online')]
        [string]
        $AgentStatus,

        [Parameter()]
        [ValidateSet('all', 'failed', 'neverDeployed', 'passed')]
        [string]
        $AgentJobResult,

        [Parameter()]
        [string]
        $ContinuationToken,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [bool]
        $Enabled
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {

        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-targets') -f $DeploymentGroupID
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APTaskGroupList.ps1
function Get-APTaskGroupList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline task groups.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline task groups based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER TaskGroupId
 
    Id of the task group.
 
    .PARAMETER Expanded
 
    'true' to recursively expand task groups. Default is 'false'.
 
    .PARAMETER TaskIdFilter
 
    Guid of the taskId to filter.
 
    .PARAMETER Deleted
 
   'true'to include deleted task groups. Default is 'false'.
 
    .PARAMETER Top
 
    Number of task groups to get.
 
    .PARAMETER ContinuationToken
 
    Gets the task groups after the continuation token provided.
 
    .PARAMETER QueryOrder
 
    Gets the results in the defined order. Default is 'CreatedOnDescending'.
 
    .INPUTS
 
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns AP task group list for 'myFirstProject'.
 
    Get-APTaskGroupList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/distributedtask/taskgroups/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $TaskGroupId,

        [Parameter()]
        [bool]
        $Expanded,

        [Parameter()]
        [string]
        $TaskIdFilter,

        [Parameter()]
        [bool]
        $Deleted,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [string]
        $ContinuationToken,

        [Parameter()]
        [ValidateSet('createdOnAscending', 'createdOnDescending')]
        [string]
        $QueryOrder
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'taskgroup-taskgroups'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APTeamList.ps1
function Get-APTeamList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline group entitlements.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline group entitlements based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Mine
 
    If true return all the teams requesting user is member, otherwise return all the teams user has read access
 
    .PARAMETER Top
 
    Maximum number of teams to return.
 
    .PARAMETER Skip
 
    Number of teams to skip.
 
    .INPUTS
     
    None, does not support the pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines account(s)
 
    .EXAMPLE
 
    Returns AP team list for 'myCollection'.
 
    Get-APTeamList -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiVersion 5.0-preview
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/core/teams/get%20all%20teams?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [bool]
        $Mine,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [int]
        $Skip
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'team-teams'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APUser.ps1
function Get-APUser
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipeline user.
 
    .DESCRIPTION
 
    Returns Azure Pipeline user by user descriptor.
    The descriptor can be retrieved by using Get-APUserList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER UserDescriptor
 
    The descriptor of the desired user.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines account(s)
 
    .EXAMPLE
 
    Returns AP user with the user descriptor of 'aad.OWRjNmIjMtZjNjY3ZDQ0LWIzOTgtZmYyMTM4N2E3NGJj' for 'myCollection'.
 
    Get-APUser -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiVersion 5.0-preview -UserDescriptor 'aad.OWRjNmIjMtZjNjY3ZDQ0LWIzOTgtZmYyMTM4N2E3NGJj'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/users/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string]
        $UserDescriptor
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        If ($ApiVersion -notmatch '5.*')
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: User list is not supported in api versions earlier the 5.0." -ErrorAction 'Stop'
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'graph-userId') -f $UserDescriptor
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APUserList.ps1
function Get-APUserList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline users.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline users based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER SubjectTypes
 
    A comma separated list of user subject subtypes to reduce the retrieved results, e.g. msa’, ‘aad’, ‘svc’ (service identity), ‘imp’ (imported identity), etc.
 
    .PARAMETER ContinuationToken
 
    An opaque data blob that allows the next page of data to resume immediately after where the previous page ended. The only reliable way to know if there is more data left is the presence of a continuation token.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines account(s)
 
    .EXAMPLE
 
    Returns AP user list for 'myCollection'.
 
    Get-APUserList -Instance 'https://dev.azure.com' -Collection 'myCollection' -ApiVersion 5.0-preview
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/users/list?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
        
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter()]
        [string[]]
        $SubjectTypes,

        [Parameter()]
        [string]
        $ContinuationToken
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        If ($ApiVersion -notmatch '5.*')
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: User list is not supported in api versions earlier the 5.0." -ErrorAction 'Stop'
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'graph-users'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APVariableGroup.ps1
function Get-APVariableGroup
{
    <#
    .SYNOPSIS
 
    Returns an Azure Pipeline variable group.
 
    .DESCRIPTION
 
    Returns an Azure Pipeline variable group by group id.
    The id can be retrieved by using Get-APVariableGroupList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER GroupId
 
    Id of the variable group.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Returns AP variable group with group id of '7' for 'myFirstProject'.
 
    Get-APVariableGroup -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -GroupId 7
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/distributedtask/variablegroups/get?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [string]
        $GroupId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {

        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-variablegroupId') -f $GroupId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APVariableGroupList.ps1
function Get-APVariableGroupList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline variable groups.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline variable groups based on a filter query.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER GroupName
     
    Name of variable group.
 
    .PARAMETER ActionFilter
     
    Action filter for the variable group. It specifies the action which can be performed on the variable groups.
 
    .PARAMETER Top
     
    Number of variable groups to get.
 
    .PARAMETER ContinuationToken
     
    Gets the releases after the continuation token provided.
 
    .PARAMETER QueryOrder
     
    Gets the results in the defined order. Default is 'IdDescending'.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines release definition(s)
 
    .EXAMPLE
 
    Returns AP variable group list for 'myFirstProject'.
 
    Get-APVariableGroupList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/distributedtask/variablegroups/get%20variable%20groups?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter()]
        [string]
        $GroupName,

        [Parameter()]
        [string]
        [ValidateSet('manage', 'none', 'use')]
        $ActionFilter,

        [Parameter()]
        [int]
        $Top,

        [Parameter()]
        [int]
        $ContinuationToken,

        [Parameter()]
        [ValidateSet('idAscending', 'idDescending')]
        [string]
        $QueryOrder
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'distributedtask-variablegroups'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Get-APWidget.ps1
function Get-APWidget
{
    <#
    .SYNOPSIS
 
    Returns Azure Pipeline widget from a dashboard.
 
    .DESCRIPTION
 
    Returns Azure Pipeline widget from a dashboard based by dashboard id.
    The id can be retrieved by using Get-APDashboardList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DashboardId
     
    ID of the dashboard to read.
 
    .PARAMETER WidgetId
 
    ID of the widget.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines widget.
 
    .EXAMPLE
 
    Returns the Azure Pipelines widget with the id of '7938afd-d935-4731-ihdo-5149849181' from the dashboard with the id of '1238afd-d935-4731-ac6e-154888894b304'.
 
    Get-APWidget -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DashboardId '1238afd-d935-4731-ac6e-154888894b304' -WidgetId '7938afd-d935-4731-ihdo-5149849181'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/dashboard/widgets/get%20widget?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $DashboardId,

        [Parameter(Mandatory)]
        [string]
        $WidgetId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'dashboard-widgetId') -f $DashboardId, $WidgetId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Get-APWidgetList.ps1
function Get-APWidgetList
{
    <#
    .SYNOPSIS
 
    Returns a list of Azure Pipeline widgets.
 
    .DESCRIPTION
 
    Returns a list of Azure Pipeline widgets based on the dashboard id.
    The id can be retrieved by using Get-APWidgetList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DashboardId
     
    ID of the dashboard to read.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines widget(s).
 
    .EXAMPLE
 
    Returns a list of Azure DevOps widgets for the 'myFirstProject.
 
    Get-APWidgetList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/dashboard/widgets/get%20widgets?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $DashboardId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'dashboard-widgets') -f $DashboardId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Install-APAgent.ps1
Function Install-APAgent
{
    <#
    .SYNOPSIS
 
    Installs a Azure Pipelines agent on the server executing the function.
 
    .DESCRIPTION
 
    Installs a Azure Pipelines agent.
    The agent can be configured to listen to a pool or a deployment group.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER Pool
 
    The pool name.
 
    .PARAMETER DeploymentGroupName
 
    The deployment group name.
 
    .PARAMETER DeploymentGroupTag
 
    The deployment group tags.
 
    .PARAMETER Platform
 
    Operating system platform.
 
    .PARAMETER PatAuthentication
     
    Authenticate with a personal access token.
 
    .PARAMETER IntegratedAuthentication
     
    Authenticate with a integrated credentials.
 
    .PARAMETER NegotiateAuthentication
     
    Authenticate with a negotiation, this requires a credential.
 
    .PARAMETER ProxyUrl
     
    The url of the proxy.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to authenticate.
     
    .PARAMETER WindowsLogonCredential
     
    Specifies a user account that will run the windows service.
 
    .PARAMETER AgentWorkingFolder
     
    Agent's working directory, this must be unique to the agent, defaults to '_work'.
 
    .PARAMETER RootAgentFolder
     
    The directory where the agent will be installed, defaults to 'Agents'.
 
    .INPUTS
 
    None, does not support pipeline.
 
    .OUTPUTS
 
    String. Install-APAgent returns log from configuration.
 
    .EXAMPLE
 
    Installs a windows deployment group agent with PAT authentication.
 
    Install-Agent -PatAuthentication -PersonalAccessToken 'myToken' -DeploymentGroupName 'Dev' -DeploymentGroupTag 'myTag' -Collection 'myCollection' -TeamProject 'AzurePipelinesPS' -Platform 'Windows'
 
    .EXAMPLE
 
    Installs a linux pool agent with negotiation authentiaction.
 
    Install-Agent -NegotiateAuthentication -Credential $pscredential -Pool 'Default' -Collection 'myCollection' -TeamProject 'AzurePipelinesPS' -Platform 'Linux'
 
    .LINK
 
    https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=vsts
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory)]
        [uri]
        $Instance,

        [Parameter(Mandatory)]
        [string]
        $Collection,

        [Parameter(Mandatory)]
        [string]
        $Project,

        [Parameter(Mandatory)]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = "ByPatAuthenticationPool")]
        [Parameter(ParameterSetName = "ByPatAuthenticationDeploymentGroup")]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(Mandatory,
            ParameterSetName = "ByNegotiateAuthenticationPool")]
        [Parameter(Mandatory,
            ParameterSetName = "ByNegotiateAuthenticationDeploymentGroup")]
        [pscredential]
        $Credential,

        [Parameter(Mandatory,
            ParameterSetName = "ByPatAuthenticationPool")]
        [Parameter(Mandatory,
            ParameterSetName = "ByIntegratedAuthenticationPool")]
        [Parameter(Mandatory,
            ParameterSetName = "ByNegotiateAuthenticationPool")]
        [string]
        $Pool,

        [Parameter()]
        [string]
        [Parameter(Mandatory,
            ParameterSetName = "ByPatAuthenticationDeploymentGroup")]
        [Parameter(Mandatory,
            ParameterSetName = "ByIntegratedAuthenticationDeploymentGroup")]
        [Parameter(Mandatory,
            ParameterSetName = "ByNegotiateAuthenticationDeploymentGroup")]
        $DeploymentGroupName,

        [Parameter()]
        [string[]]
        $DeploymentGroupTag,

        [Parameter(Mandatory)]
        [ValidateSet('Windows', 'ubuntu.16.04-x64', 'ubuntu.14.04-x64')]
        [string]
        $Platform,

        [Parameter(ParameterSetName = "ByPatAuthenticationPool")]
        [Parameter(ParameterSetName = "ByPatAuthenticationDeploymentGroup")]
        [switch]
        $PatAuthentication,

        [Parameter(ParameterSetName = "ByIntegratedAuthenticationPool")]
        [Parameter(ParameterSetName = "ByIntegratedAuthenticationDeploymentGroup")]
        [switch]
        $IntegratedAuthentication,

        [Parameter(ParameterSetName = "ByNegotiateAuthenticationPool")]
        [Parameter(ParameterSetName = "ByNegotiateAuthenticationDeploymentGroup")]
        [switch]
        $NegotiateAuthentication,

        [Parameter(ParameterSetName = "ByPatAuthenticationPool")]
        [Parameter(ParameterSetName = "ByIntegratedAuthenticationPool")]
        [Parameter(ParameterSetName = "ByNegotiateAuthenticationPool")]
        [string]
        $ProxyUrl,

        [Parameter()]
        [pscredential]
        $WindowsLogonCredential,

        [Parameter()]
        [string]
        $AgentWorkingFolder = '_work',

        [Parameter()]
        [string]
        $RootAgentFolder = 'C:\vstsAgents'
    )

    $arguments = @(
        "--unattended"
        "--projectName `"{0}`"" -f $Project
        "--url $Instance$Collection"
        "--work `"{0}`"" -f $AgentWorkingFolder
        "--runasservice"
    )
    If ($Pool)
    {
        $arguments += "--pool `"{0}`"" -f $Pool
    }
    If ($DeploymentGroupName)
    {
        Write-Verbose "Configuring agent for deployment group: [$DeploymentGroupName]"
        $arguments += "--deploymentGroup"
        $arguments += "--deploymentGroupName `"{0}`"" -f $DeploymentGroupName
        If ($DeploymentGroupTag)
        {
            Write-Verbose ("Adding the following deployment tags: [{0}]" -f ($DeploymentGroupTag -join ', '))
            $arguments += "--addDeploymentGroupTags"
            $arguments += ("--deploymentGroupTags `"{0}`"" -f ($DeploymentGroupTag -join ', '))
        }
    }
    If ($WindowsLogonCredential.UserName)
    {
        Write-Verbose "Configuring the target agent to use a windows logon account: [$($WindowsLogonCredential.Username)]"
        $arguments += ("--windowsLogonAccount {0}" -f $WindowsLogonCredential.UserName)
        $arguments += ("--windowsLogonPassword `"{0}`"" -f $WindowsLogonCredential.GetNetworkCredential().Password)
    }
    If ($PatAuthentication)
    {
        $plainTextPat = Unprotect-APSecurePersonalAccessToken -PersonalAccessToken $PersonalAccessToken
        If (-not($plainTextPat))
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: A personal access Token is required to use PAT authentications" -ErrorAction Stop
        }
        Write-Verbose "Authenticating using [PAT]"
        $arguments += "--auth Pat"
        $arguments += "--token $plainTextPat"
    }
    If ($IntegratedAuthentication)
    {
        Write-Verbose "Authenticating using [Integrated]"
        $arguments += "--auth integrated"
    }
    If ($NegotiateAuthentication)
    {
        Write-Verbose "Authenticating using [Negotiate]"
        $arguments += "--auth negotiate"
        $arguments += ("--userName {0}" -f $Credential.UserName)
        $arguments += ("--password {0}" -f $Credential.GetNetworkCredential().Password)
    }
    If ($ProxyUrl)
    {
        Write-Verbose "Using proxy url [$ProxyUrl]"
        $arguments += "--proxyurl $proxyUrl"
    }
    If (-not (Test-Path $RootAgentFolder))
    {
        Write-Verbose "Creating root agent path: [$RootAgentFolder]"  
        $null = New-Item -ItemType Directory -Path $RootAgentFolder
    }
    Set-Location $RootAgentFolder
    for ($i = 1; $i -lt 100; $i++)
    {
        $destFolder = 'A' + $i.ToString()
        if (-not (Test-Path ($destFolder)))
        {
            Write-Verbose "Creating destination folder: [$destFolder]"
            $null = New-Item -ItemType Directory -Path $destFolder
            Set-Location $destFolder
            break
        }
    }
    # Download agent
    $agentZip = "$PWD\agent.zip"
    $securityProtocol = @()
    $securityProtocol += [Net.ServicePointManager]::SecurityProtocol
    $securityProtocol += [Net.SecurityProtocolType]::Tls12
    [Net.ServicePointManager]::SecurityProtocol = $securityProtocol
    $WebClient = New-Object Net.WebClient
    $uri = Get-APAgentPackage -Platform $Platform -Instance $Instance -ApiVersion $ApiVersion
    If (-not($uri))
    {
        Write-Error "[$($MyInvocation.MyCommand.Name)]: Unable to locate package url!" -ErrorAction Stop
    }
    If ($ProxyUrl)
    {
        $DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy
        $WebClient.Proxy = New-Object Net.WebProxy($DefaultProxy.GetProxy($ProxyUrl), $True)
    }
    Write-Verbose "Downloading agent package from: [$uri]"
    $WebClient.DownloadFile($uri, $agentZip)
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    Write-Verbose "Extracting agent package"
    [System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD")
    Remove-Item $agentZip
    
    Write-Verbose "Configuring agent: [$arguments]"

    # Configure agent
    $arguments += "--agent {0}-{1}" -f $env:COMPUTERNAME, $destFolder
    $startprocessSplat = @{
        NoNewWindow            = $true
        Wait                   = $true
        FilePath               = "$RootAgentFolder\$destFolder\config.cmd"
        ArgumentList           = $arguments
        WorkingDirectory       = "$RootAgentFolder\$destFolder"
        RedirectStandardError  = 'errorResults.log'
        RedirectStandardOutput = 'results.log'
    }
    Start-Process @startprocessSplat
    Get-Content .\results.log
    $errorResults = Get-Content .\errorResults.log
    If ($errorResults)
    {
        Write-Error $errorResults
    }
}

# Install-APPSModule.ps1
function Install-APPSModule
{
    <#
    .SYNOPSIS
 
    Installs a module from an Azure Pipelines feed.
 
    .DESCRIPTION
 
    Installs a module from an Azure Pipelines feed using the personal access token from the session configuration.
    A list of modules can be retrieved with Find-APPSModule.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
 
    Specifies the exact names of modules to install from the online gallery. A comma-separated list of module names is accepted. The module name must match the module name in the repository. Use Find-APPSModule to get a list of module names.
 
    .PARAMETER Repository
 
    Use the Repository parameter to specify which repository is used to download and install a module. Used when multiple repositories are registered. Specifies the name of a registered repository in the Install-APPSModule command. To register a repository, use Register-APPSRepository. To display registered repositories, use Get-PSRepository.
 
    .PARAMETER Scope
 
    Specifies the installation scope of the module. The acceptable values for this parameter are AllUsers and CurrentUser.
 
    .PARAMETER RequiredVersion
 
    Specifies the exact version of a single module to install. If there is no match in the repository for the specified version, an error is displayed. If you want to install multiple modules, you cannot use RequiredVersion.
 
    .PARAMETER MaximumVersion
 
    Specifies the maximum, or latest, version of the module to include in the search results. MaximumVersion and RequiredVersion cannot be used in the same command.
 
    .PARAMETER MinimumVersion
 
    Specifies the minimum version of the module to include in results. MinimumVersion and RequiredVersion cannot be used in the same command.
 
    .PARAMETER AllowClobber
 
    Overrides warning messages about installation conflicts about existing commands on a computer. Overwrites existing commands that have the same name as commands being installed by a module.
 
    .PARAMETER SkipPublisherCheck
 
    Allows you to install a newer version of a module that already exists on your computer. For example, when an existing module is digitally signed by a trusted publisher but the new version is not digitally signed by a trusted publisher.
 
    .PARAMETER Force
 
    Installs a module and overrides warning messages about module installation conflicts. If a module with the same name already exists on the computer, Force allows for multiple versions to be installed. If there is an existing module with the same name and version, Force overwrites that version.
 
    .PARAMETER AcceptLicense
 
    For modules that require a license, AcceptLicense automatically accepts the license agreement during installation. For more information, see Modules Requiring License Acceptance.
 
    .PARAMETER AllowPrerelease
 
    Includes in the results modules marked as a pre-release.
     
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines Module.
 
    .EXAMPLE
     
    .LINK
 
    https://docs.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-6
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string[]]
        $Name,

        [Parameter()]
        [string[]]
        $Repository,

        [Parameter()]
        [ValidateSet('AllUsers', 'CurrentUser')]
        [string]
        $Scope,

        [Parameter()]
        [string]
        $RequiredVersion,

        [Parameter()]
        [string]
        $MinimumVersion,

        [Parameter()]
        [string]
        $MaximumVersion,

        [Parameter()]
        [switch]
        $AllowClobber,

        [Parameter()]
        [switch]
        $SkipPublisherCheck,

        [Parameter()]
        [switch]
        $Force,

        [Parameter()]
        [switch]
        $AllowPrerelease,

        [Parameter()]
        [switch]
        $AcceptLicense
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
            }
        }
    }
        
    process
    {
        If ($PersonalAccessToken)
        {
            $Credential = [pscredential]::new('NA', $PersonalAccessToken)
        }
        $installModuleSplat = @{
            Name       = $Name
            Credential = $Credential
        }
        If ($Repository)
        {
            $installModuleSplat.Repository = $Repository
        }
        If ($Scope)
        {
            $installModuleSplat.Scope = $Scope
        }
        If ($Proxy)
        {
            $installModuleSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $installModuleSplat.ProxyCredential = $ProxyCredential
        }
        If ($SkipPublisherCheck)
        {
            $installModuleSplat.SkipPublisherCheck = $SkipPublisherCheck
        }
        If ($MinimumVersion)
        {
            $installModuleSplat.MinimumVersion = $MinimumVersion
        }
        If ($MaximumVersion)
        {
            $installModuleSplat.MaximumVersion = $MaximumVersion
        }
        If ($RequiredVersion)
        {
            $installModuleSplat.Scope = $RequiredVersion
        }
        If ($AllowPrerelease)
        {
            $installModuleSplat.AllowPrerelease = $AllowPrerelease
        }
        If ($AcceptLicense)
        {
            $installModuleSplat.AcceptLicense = $AcceptLicense
        }
        If ($AllowClobber)
        {
            $installModuleSplat.AllowClobber = $AllowClobber
        }
        If ($Force)
        {
            $installModuleSplat.Force = $Force
        }
        Install-Module @installModuleSplat
    }
    
    end
    {
    }
}
# Invoke-APNugetPackageDownload.ps1
function Invoke-APNugetPackageDownload
{
    <#
    .SYNOPSIS
 
    Downloads an Azure Pipeline nuget package.
 
    .DESCRIPTION
 
    Downloads an Azure Pipeline nuget package by feed id, package name and package version.
    The id can be retrieved by using Get-APFeedList.
    The package name and version can be retrieved by using Get-APPackageList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
    For Azure DevOps the value should be https://dev.azure.com/.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedId
     
    The name or id of the feed.
 
    .PARAMETER PackageName
 
    The name of the package.
 
    .PARAMETER PackageVersion
 
    The version of the package.
 
    .PARAMETER Path
 
    The directory to output the file to.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Invoke-APNugetPackageDownload does not generate any output.
 
    .EXAMPLE
 
    Returns the build with the id of '7' for the 'myFirstProject.
 
    Invoke-APNugetPackageDownload -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -BuildId 7
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifactspackagetypes/nuget/download%20package?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,
        
        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [string]
        $FeedId,
        
        [Parameter(Mandatory)]
        [string]
        $PackageName,

        [Parameter(Mandatory)]
        [string]
        $PackageVersion, 

        [Parameter(Mandatory)]
        [string]
        $Path
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $_outputPath = "{0}\{1}.{2}.nuget" -f $Path, $PackageName, $PackageVersion
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'feed-packageContent') -f $FeedId, $PackageName, $PackageVersion
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'GET'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
            Path                = $_outputPath
        }
        Invoke-APRestMethod @invokeAPRestMethodSplat
    }
    
    end
    {
    }
}
# Invoke-APPolicyEvaluation.ps1
function Invoke-APPolicyEvaluation
{
    <#
    .SYNOPSIS
 
    Requeues a Azure Pipeline policy evaluation.
 
    .DESCRIPTION
 
    Requeues a Azure Pipeline policy evaluation by evaluation id.
    The id can be retrieved by using Get-APPolicyEvaluationList.
 
    Some policies define a "requeue" action which performs some policy-specific operation.
    You can trigger this operation by updating an existing policy evaluation and setting the PolicyEvaluationRecord.Status field to Queued.
    Although any policy evaluation can be requeued, at present only build policies perform any action in response.
    Requeueing a build policy will queue a new build to run (cancelling any existing build which is running).
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER EvaluationId
     
    Id of the policy evaluation.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy evaluation(s)
 
    .EXAMPLE
 
    Requeues policy evaluation with the id of '7'.
 
    Get-APPolicyEvaluation -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -EvaluationId '7'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/evaluations/requeue%20policy%20evaluation?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $EvaluationId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-evaluationId') -f $EvaluationId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'PATCH'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Invoke-APRestMethod.ps1
function Invoke-APRestMethod
{
    <#
    .SYNOPSIS
 
    Invokes an Azure Pipelines PS rest method.
 
    .DESCRIPTION
 
    Invokes an Azure Pipelines PS rest method.
 
    .PARAMETER Method
     
    Specifies the method used for the web request.
 
    .PARAMETER Body
     
    Specifies the body of the request. The body is the content of the request that follows the headers.
 
    .PARAMETER ContentType
     
    Specifies the content type of the web request. If this parameter is omitted and the request method is POST, Invoke-RestMethod sets the content type to application/x-www-form-urlencoded. Otherwise, the content type is not specified in the call.
 
    .PARAMETER Uri
 
    Specifies the Uniform Resource Identifier (URI) of the Internet resource to which the web request is sent. This parameter supports HTTP, HTTPS, FTP, and FILE values.
 
    .PARAMETER PersonalAccessToken
 
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request. The default is the Personal Access Token if it is defined, otherwise it is the current user.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Path
 
    The directory to output files to.
     
    .OUTPUTS
 
    System.Int64, System.String, System.Xml.XmlDocument, The output of the cmdlet depends upon the format of the content that is retrieved.
 
    .OUTPUTS
 
    PSObject, If the request returns JSON strings, Invoke-RestMethod returns a PSObject that represents the strings.
 
    .EXAMPLE
 
    Invokes AP rest method 'PATCH' against the uri 'https://dev.azure.com/release/releases?api-version=5.0-preview.6'.
 
    Invoke-APRestMethod -Method PATCH -Body $Body -ContentType 'application/json' -Uri 'https://dev.azure.com/release/releases?api-version=5.0-preview.6'
 
    .LINK
 
    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-6
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory)]
        [string]
        $Method,

        [Parameter()]
        [psobject]
        $Body,

        [Parameter(Mandatory)]
        [uri]
        $Uri,

        [Parameter()]
        [string]
        $ContentType,

        [Parameter()]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter()]
        [pscredential]
        $Credential,

        [Parameter()]
        [string]
        $Proxy,

        [Parameter()]
        [pscredential]
        $ProxyCredential, 

        [Parameter()]
        [string]
        $Path
    )

    begin
    {
    }
    
    process
    {
        $invokeRestMethodSplat = @{
            ContentType     = $ContentType
            Method          = $Method
            UseBasicParsing = $true
            Uri             = $uri.AbsoluteUri
        }
        If ($Body)
        {
            $invokeRestMethodSplat.Body = $Body | ConvertTo-Json -Depth 20 
        }
        If ($Proxy)
        {
            $invokeRestMethodSplat.Proxy = $Proxy
            If ($ProxyCredential)
            {
                $invokeRestMethodSplat.ProxyCredential = $ProxyCredential
            }
            else
            {
                $invokeRestMethodSplat.ProxyUseDefaultCredentials = $true
            }
        }
        If ($Path)
        {
            $invokeRestMethodSplat.OutFile = $Path
        }
        $authenticatedRestMethodSplat = Set-APAuthenticationType -InputObject $invokeRestMethodSplat -Credential $Credential -PersonalAccessToken $PersonalAccessToken
        $results = Invoke-RestMethod @authenticatedRestMethodSplat
        Return $results
    }
    
    end
    {
    }
}

# New-APBuild.ps1
function New-APBuild
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipeline build.
 
    .DESCRIPTION
 
    Creates an Azure Pipeline build by build definition name.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
 
    The name of the build definition to queue.
 
    .PARAMETER Path
 
    The path of the build definition to queue.
 
    .PARAMETER IgnoreWarnings
 
    Undocumented.
 
    .PARAMETER CheckInTicket
 
    Undocumented.
 
    .PARAMETER SourceBuildId
 
    Undocumented.
 
    .PARAMETER SourceBranch
 
    The branch to get sources.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $Name,

        [Parameter()]
        [string]
        $Path,

        [Parameter()]
        [bool]
        $IgnoreWarnings,

        [Parameter()]
        [string]
        $CheckInTicket,

        [Parameter()]
        [int]
        $SourceBuildId,

        [Parameter()]
        [string]
        $SourceBranch
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $getAPBuildDefinitionListSplat = @{
            Collection = $Collection
            Instance   = $Instance
            Project    = $Project
            ApiVersion = $ApiVersion
            Name       = $Name
        }
        If ($Credential)
        {
            $getAPBuildDefinitionListSplat.Credential = $Credential
        }
        If ($PersonalAccessToken)
        {
            $getAPBuildDefinitionListSplat.PersonalAccessToken = $PersonalAccessToken
        }
        If ($Proxy)
        {
            $getAPBuildDefinitionListSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $getAPBuildDefinitionListSplat.ProxyCredential = $ProxyCredential
        }
        If ($Path)
        {
            $getAPBuildDefinitionListSplat.Path = $Path
        }
        $definition = Get-APBuildDefinitionList @getAPBuildDefinitionListSplat
        Foreach ($_definition in $definition)
        {
            $body = @{
                definition = $_definition
            }
            If ($SourceBranch)
            {
                $body.SourceBranch = $SourceBranch
            }
            $apiEndpoint = Get-APApiEndpoint -ApiType 'build-builds'
            $setAPUriSplat = @{
                Collection  = $Collection
                Instance    = $Instance
                Project     = $Project
                ApiVersion  = $ApiVersion
                ApiEndpoint = $apiEndpoint
            }
            [uri] $uri = Set-APUri @setAPUriSplat
            $invokeAPRestMethodSplat = @{
                Method              = 'POST'
                Uri                 = $uri
                Credential          = $Credential
                PersonalAccessToken = $PersonalAccessToken
                Body                = $body
                ContentType         = 'application/json'
                Proxy               = $Proxy
                ProxyCredential     = $ProxyCredential
            }
            $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
            If ($results.value)
            {
                $results.value
            }
            else
            {
                $results
            }
        }
    }
    
    end
    {
    }
}
# New-APDashboard.ps1
function New-APDashboard
{
    <#
    .SYNOPSIS
 
    Creates a new Azure Pipelines dashboard.
 
    .DESCRIPTION
 
    Creates a new Azure Pipelines dashboard for the project provided.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
 
    The name of the dashboard.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines dashboard.
 
    .EXAMPLE
 
    Creates a dashboard with the name of 'myFirstDashboard' for 'myFirstProject'
 
    New-APDashboard -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -Name 'myFirstDashboard'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/dashboard/dashboards/create?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $Name
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = @{
            Name = $Name
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'dashboard-dashboards'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# New-APFeed.ps1
function New-APFeed
{
    <#
    .SYNOPSIS
 
    Create a feed, a container for various package types.
 
    .DESCRIPTION
 
    Create a feed, a container for various package types.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
 
    A name for the feed. feed names must follow these rules: Must not exceed 64 characters Must not contain whitespaces Must not start with an underscore or a period Must not end with a period Must not contain any of the following illegal characters: , |, /, \\, ?, :, &, $, *, \", #, [, ] ]]>
 
    .PARAMETER FeedCapabilities
 
    Supported capabilities of a feed.
 
    .PARAMETER Description
 
    A description for the feed. Descriptions must not exceed 255 characters.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines feed.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/feed/feeds/queue?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $Name,

        [Parameter()]
        [ValidateSet('defaultCapabilities', 'none', 'underMaintenance', 'upstreamV2')]
        [string]
        $FeedCapabilities,

        [Parameter()]
        [string]
        $Description
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $body = @{
            Name = $Name
        }
        If ($FeedCapabilities)
        {
            $body.FeedCapabilities = $FeedCapabilities
        }
        If ($Description)
        {
            $body.Description = $Description
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'feed-feeds'
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# New-APGitBranch.ps1
function New-APGitBranch
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipeline Git branch.
 
    .DESCRIPTION
 
    Creates an Azure Pipeline Git branch based on the object id.
    The object id can be retrieved by using Get-APGitRefList.
    A commit is required to create a new branch so this command creates and removes a file named after a randomly generated guid.
    Both commits can be seen in the new branch's history.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER RepositoryId
 
    The name or ID of the repository.
 
    .PARAMETER ObjectId
 
    The branch object id to create the new branch from. Use Get-APGitRefList to identify the object id.
 
    .PARAMETER BranchName
 
    The new branch name.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines Git ref.
 
    .EXAMPLE
 
    Creates a new git branch in the 'myRepository' with the name of 'myNewBranch' based on the branch object id of '50114dacf4ed256f37e397ded65188400d84b0831bd'
 
    New-APGitBranch -Session 'mySession' -RepositoryId 'myRepository' -BranchName 'refs/heads/myNewBranch' -OldObjectId '50114dacf4ed256f37e397ded65188400d84b0831bd'
     
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/create?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $RepositoryId, 

        [Parameter(Mandatory)]
        [string]
        $ObjectId, 

        [Parameter(Mandatory)]
        [string]
        $BranchName
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        # Path is used to create a file at the root of the repository and then remove it.
        $path = "/{0}" -f (New-Guid).Guid
        $body = @{
            refUpdates = @(
                @{
                    name        = $BranchName
                    oldObjectId = $ObjectId
                }
            )
            commits    = @(
                @{
                    comment = "Created a new file $path"
                    changes = @(
                        @{
                            changeType = 'add'
                            item       = @{
                                path = $path
                            }
                            newContent = @{
                                content     = "# $BranchName"
                                contentType = 'rawtext'
                            }
                        }
                    )
                }
            )
        }

        $apiEndpoint = (Get-APApiEndpoint -ApiType 'git-pushes') -f $RepositoryId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results)
        {
            $removeAPGitFileSplat = @{
                Instance     = $Instance
                Collection   = $Collection
                Project      = $Project
                ApiVersion   = $ApiVersion
                RepositoryId = $RepositoryId
                BranchName   = $BranchName
                ObjectId     = $results.refUpdates.newObjectId
                Path         = $path
            }
            If ($PersonalAccessToken)
            {
                $removeAPGitFileSplat.PersonalAccessToken = $PersonalAccessToken
            }
            If ($Credential)
            {
                $removeAPGitFileSplat.Credential = $Credential
            }
            If ($Proxy)
            {
                $removeAPGitFileSplat.Proxy = $Proxy
            }
            If ($ProxyCredential)
            {
                $removeAPGitFileSplat.ProxyCredential = $ProxyCredential
            }
            Remove-APGitFile @removeAPGitFileSplat
        }
    }
    
    end
    {
    }
}
# New-APNotificationSubscription.ps1
function New-APNotificationSubscription
{
    <#
    .SYNOPSIS
 
    Creates a new notification subscription.
 
    .DESCRIPTION
 
    Creates a new notification subscription.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER SubscriberFlags
 
    The flags that determine the type of notification delivery.
 
    .PARAMETER Template
 
    The template provided by Get-APNotificationSubscriptionList.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines subscription list.
 
    .EXAMPLE
     
    Creates a 'build failure' subscription for a list of teams. The subscription will send a notification to the entire team if a build fails.
 
    # Gets a list of teams and outputs it to grid view, the grid view acts as pick list.
    $teams = (Get-APTeamList -Session $session | Out-GridView -PassThru)
    Foreach ($_team in $teams)
    {
        # Get the build fails notification subscription template.
        $template = Get-APNotificationSubscriptionTemplateList -Session $session | Where-Object { $PSitem.Description -match 'build fails' }
 
        # Add the team as the subscription subscriber to the template.
        $template | Add-Member -NotePropertyName 'Subscriber' -NotePropertyValue $_team
 
        # Add the teams project id as the scope id to the template.
        $template | Add-Member -NotePropertyName 'Scope' -NotePropertyValue @{ Id = $_team.ProjectId }
 
        # Add the channel type to the template.
        $template | Add-Member -NotePropertyName 'Channel' -NotePropertyValue @{type = 'Group'; useCustomAddress = $false }
 
        # Create the notification subscription from the template with the 'isTeam' flag.
        New-APNotificationSubscription -Session $session -Template $template -SubscriberFlags 'isTeam'
    }
 
    .EXAMPLE
 
    Creates a 'build failure' subscription for a list of teams. The subscription will send a notification to the members of the team's role.
    Roles:
        Last changes by
        Requested by
        Requested for
        Deleted by
 
    # Gets a list of teams and outputs it to grid view, the grid view acts as pick list.
    $teams = (Get-APTeamList -Session $session | Out-GridView -PassThru)
    Foreach ($_team in $teams)
    {
        # Get the build fails notification subscription template.
        $template = Get-APNotificationSubscriptionTemplateList -Session $session | Where-Object { $PSitem.Description -match 'build fails' }
         
        # Add the team as the subscription subscriber to the template.
        $template | Add-Member -NotePropertyName 'Subscriber' -NotePropertyValue $_team
         
        # Add the teams project id as the scope id to the template.
        $template | Add-Member -NotePropertyName 'Scope' -NotePropertyValue @{ Id = $_team.ProjectId }
 
        # Add the channel type to the template.
        $template | Add-Member -NotePropertyName 'Channel' -NotePropertyValue @{type = 'User'; useCustomAddress = $false }
 
        # Updates the filter from expression to 'Actor'.
        $template.Filter | Add-Member -NotePropertyName 'type' -NotePropertyValue 'Actor' -Force
         
        # Updates the filter inclusions to include the roles.
        $template.Filter | Add-Member -NotePropertyName 'inclusions' -NotePropertyValue @("lastChangedBy", "requestedBy", "requestedFor", "deletedBy") -Force
 
        # Updates the filter exclusions to exclude none.
        $template.Filter | Add-Member -NotePropertyName 'exclusions' -NotePropertyValue @() -Force
 
        # Create the notification subscription from the template with the 'isTeam' flag.
        New-APNotificationSubscription -Session $session -Template $template -SubscriberFlags 'isTeam'
    }
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/notification/subscriptions/get%20subscription%20templates?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [ValidateSet('deliveryPreferencesEditable', 'isGroup', 'isTeam', 'isUser', 'none', 'supportsEachMemberDelivery', 'supportsNoDelivery', 'supportsPreferredEmailAddressDelivery')]
        [string]
        $SubscriberFlags,

        [Parameter(Mandatory)]
        [PSobject]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $Template | Add-Member -NotePropertyName 'SubscriberFlags' -NotePropertyValue $SubscriberFlags -Force
        $body = $Template
        $apiEndpoint = Get-APApiEndpoint -ApiType 'notification-subscriptions'
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# New-APPolicyConfiguration.ps1
function New-APPolicyConfiguration
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipeline policy configuration of a given policy type.
 
    .DESCRIPTION
 
    Creates an Azure Pipeline policy configuration of a given policy type.
    The type can be retrieved by using Get-APPolicyTypeList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    A policy template. A modified policy type object.
    The policy type can be retrived with Get-APPolicyTypeList.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy configuration(s)
 
    .EXAMPLE
 
    Creates a policy configuration with a single minimum reviewer. The scope will need updated to be applied to a specific repository.
 
    $session = 'mySession'
    $types = Get-APPolicyTypeList -Session $session
    $template = @{
        isEnabled = $true
        isBlocking = $false
        type = $types.Where( {$PSitem.DisplayName -eq 'Minimum number of reviewers'}) | Select-Object -Property 'Id'
        settings = @{
            minimumApproverCount = 1
            creatorVoteCounts = $false
            scope = @(
                @{
                    repositoryId = $null
                    refName = 'refs/heads/master'
                    matchKind = 'exact'
                }
            )
        }
    }
    New-APPolicyConfiguration -Session $Session -Template $template
     
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations/create?view=azure-devops-rest-5.1
 
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [object]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = Get-APApiEndpoint -ApiType 'policy-configurations'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# New-APRelease.ps1
function New-APRelease
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipeline release.
 
    .DESCRIPTION
 
    Creates an Azure Pipeline release by definition id.
    The id can be retrieved by using Get-APReleaseList.
 
  .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DefinitionId
 
    Sets definition Id to create a release.
 
    .PARAMETER BuildId
 
    Id of the build to use as the artifact source, defaults to the latest build id.
    The buildId parameter does not support releases with multiple artifacts.
 
    .PARAMETER Description
 
    Sets description to create a release.
 
    .PARAMETER Reason
 
    Sets reason to create a release.
 
    .PARAMETER ManualEnvironments
 
    Sets list of environments to manual as condition.
 
    .PARAMETER IsDraft
 
    Sets 'true' to create release in draft mode, 'false' otherwise, defaults to 'false'.
 
    .PARAMETER Variables
     
    Sets list of release variables to be overridden at deployment time.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines variable group.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/create?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $DefinitionId,

        [Parameter()]
        [int]
        $BuildId,

        [Parameter()]
        [string]
        $Description,

        [Parameter()]
        [ValidateSet('continuousIntegration', 'manual', 'none', 'pullRequest', 'schedule')]
        [string]
        $Reason,

        [Parameter()]
        [string[]]
        $ManualEnvironments,

        [Parameter()]
        [string]
        $IsDraft = $false,

        [Parameter()]
        [hashtable]
        $Variables
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $getAPReleaseDefinitionSplat = @{
            Collection   = $Collection
            Project      = $Project
            ApiVersion   = $ApiVersion
            Instance     = $Instance
            DefinitionId = $DefinitionId
        }
        If ($PersonalAccessToken)
        {
            $getAPReleaseDefinitionSplat.PersonalAccessToken = $PersonalAccessToken
        }
        If ($Credential)
        {
            $getAPReleaseDefinitionSplat.Credential = $Credential
        }
        If ($Proxy)
        {
            $getAPReleaseDefinitionSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $getAPReleaseDefinitionSplat.ProxyCredential = $ProxyCredential
        }
        $definition = Get-APReleaseDefinition @getAPReleaseDefinitionSplat
        $_artifacts = @()
        Foreach ($artifactSource in $Definition.artifacts)
        {
            $getAPBuildDefinitionSplat = @{
                Collection = $Collection
                Project    = $Project
                ApiVersion = $ApiVersion
                Instance   = $Instance
                Top        = 1
            }
            If ($BuildId)
            {
                $getAPBuildDefinitionSplat.BuildIds = $BuildId
            }
            else
            {
                $getAPBuildDefinitionSplat.Definitions = $artifactSource.definitionReference.definition.id            
            }
            If ($PersonalAccessToken)
            {
                $getAPBuildDefinitionSplat.PersonalAccessToken = $PersonalAccessToken
            }
            If ($Credential)
            {
                $getAPBuildDefinitionSplat.Credential = $Credential
            }
            If ($Proxy)
            {
                $getAPBuildDefinitionSplat.Proxy = $Proxy
            }
            If ($ProxyCredential)
            {
                $getAPBuildDefinitionSplat.ProxyCredential = $ProxyCredential
            }
            $build = Get-APBuildList @getAPBuildDefinitionSplat
            $_artifacts += @{
                alias             = $artifactSource.alias
                instanceReference = @{
                    id   = $build.id
                    name = $build.buildNumber
                }
            }
        }
        $body = @{
            DefinitionId       = $DefinitionId
            Description        = $Description
            Reason             = $Reason
            ManualEnvironments = $ManualEnvironments
            isDraft            = $IsDraft
            artifacts          = $_artifacts
        }
        If ($Variables)
        {
            $_variables = @{ }
            Foreach ($token in $Variables.Keys)
            {
                $_variables.$token = @{
                    Value = $Variables.$token
                }
            }
            $body.Variables = $_variables
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'release-releases'
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# New-APRepository.ps1
function New-APRepository
{
    <#
    .SYNOPSIS
 
    Creates and Azure Pipeline repository.
 
    .DESCRIPTION
 
    Creates and Azure Pipeline repository.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Name
 
    The name of the repository to create.
 
    .PARAMETER ParentRepository
     
    The parent repository.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Creates AP repository with the name of 'myFirstRepository' for 'myFirstProject'.
 
    New-APRepository -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -Name 'myFirstRepository'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/create?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $Name
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $getAPProjectListSplat = @{
            Collection = $Collection
            Instance   = $Instance
            ApiVersion = $ApiVersion
        }
        If ($PersonalAccessToken)
        {
            $getAPProjectListSplat.PersonalAccessToken = $PersonalAccessToken
        }
        If ($Credential)
        {
            $getAPProjectListSplat.Credential = $Credential
        }
        If ($Proxy)
        {
            $getAPProjectListSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $getAPProjectListSplat.ProxyCredential = $ProxyCredential
        }
        $projectId = Get-APProjectList @getAPProjectListSplat | Where-Object { $PSItem.Name -eq $Project } | Select-Object -ExpandProperty 'id'
        $body = @{
            name    = $Name
            project = @{
                id = $projectId
            }
        }
        $apiEndpoint = Get-APApiEndpoint -ApiType 'git-repositories'
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# New-APServiceEndpoint.ps1
function New-APServiceEndpoint
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipeline service endpoint.
 
    .DESCRIPTION
 
    Creates an Azure Pipeline service endpoint.
    The type can be retrieved by using Get-APServiceEndpointTypeList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    A service endpoint template. A modified service endpoint type object.
    The service endpoint type can be retrived with Get-APServiceEndpointTypeList.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines service endpoint(s)
 
    .EXAMPLE
 
    Creates a Jenkins service endpoint called 'myNewJenkinsEndpoint' with basic authentication.
 
    $session = 'mySession'
    $types = Get-APServiceEndpointTypeList -Session $session
    $template = @{
        name = 'myNewJenkinsEndpoint'
        description = 'My new service endpoint description'
        type = $types.Where( { $PSitem.DisplayName -eq 'Jenkins' }) | Select-Object -ExpandProperty 'Name'
        url = 'https://myJenkinsServerUrl.com'
        authorization = @{
            scheme = 'UsernamePassword'
            parameters = @{
                username = 'myUsername'
                password = 'myPassword'
            }
        }
        isReady = $true
    }
    New-APServiceEndpoint -Session $Session -Template $template
     
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/create?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [object]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = Get-APApiEndpoint -ApiType 'serviceendpoint-endpoints'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# New-APSession.ps1
Function New-APSession
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipelines session.
 
    .DESCRIPTION
 
    Creates an Azure Pipelines session.
    Use Save-APSession to persist the session data to disk.
    Save the session to a variable to pass the session to other functions.
 
    .PARAMETER SessionName
     
    The friendly name of the session.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
    See example 1.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to the project.
     
    .PARAMETER Version
     
    TFS version, this will provide the module with the api version mappings.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Name
     
    The friendly name of the mdoule data instance, configured by Save-APSession.
 
    .PARAMETER Path
     
    The path where module data will be stored, defaults to $Script:ModuleDataPath.
 
    .LINK
 
    Save-APSession
    Remove-APSession
 
    .INPUTS
 
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject. New-APSession returns a PSObject that contains the following:
        Instance
        Collection
        PersonalAccessToken
 
    .EXAMPLE
 
    Creates a session with the name of 'AzurePipelinesPS' returning it to the $session variable.
 
    $newAPSessionSplat = @{
        Collection = 'myCollection'
        Project = 'myFirstProject'
        Instance = 'https://dev.azure.com/'
        PersonalAccessToken = 'myToken'
        Version = 'vNext'
        SessionName = 'AzurePipelinesPS'
    }
    $session = New-APSession @newAPSessionSplat
 
    .EXAMPLE
 
    Creates a session with the name of 'myFirstSession' returning it to the $session variable. Then saves the session to disk for use after the session is closed.
 
    $newAPSessionSplat = @{
        Collection = 'myCollection'
        Project = 'myFirstProject'
        Instance = 'https://dev.azure.com/'
        PersonalAccessToken = 'myToken'
        Version = 'vNext'
        SessionName = 'myFirstSession'
    }
    $session = New-APSession @newAPSessionSplat
    $session | Save-APSession
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory)]
        [string]
        $SessionName,

        [Parameter(Mandatory)]
        [uri]
        $Instance,

        [Parameter(Mandatory)]
        [string]
        $Collection,

        [Parameter(Mandatory)]
        [string]
        $Project,

        [Parameter()]
        [ValidateSet('vNext', '2018 Update 2', '2018 RTW', '2017 Update 2', '2017 Update 1', '2017 RTW', '2015 Update 4', '2015 Update 3', '2015 Update 2', '2015 Update 1', '2015 RTW')]
        [Obsolete("[New-APSession]: Version has been deprecated and replaced with ApiVersion.")]
        [string]
        $Version,       

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [string]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter()]
        [string]
        $ApiVersion,

        [Parameter()]
        [string]
        $Proxy,

        [Parameter()]
        [pscredential]
        $ProxyCredential,
        
        [Parameter()]
        [string]
        $Path = $Script:ModuleDataPath
    )
    Process
    {
        If ($Version)
        {
            $ApiVersion = Get-APApiVersion -Version $Version
        }
        If (-not($ApiVersion))
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: ApiVersion is required to create a session" -ErrorAction 'Stop'
        }
        [int] $_sessionIdcount = (Get-APSession | Sort-Object -Property 'Id' | Select-Object -Last 1 -ExpandProperty 'Id') + 1
        $_session = New-Object -TypeName PSCustomObject -Property @{
            Instance    = $Instance
            Collection  = $Collection
            Project     = $Project
            ApiVersion  = $ApiVersion
            SessionName = $SessionName
            Id          = $_sessionIdcount
        }
        If ($PersonalAccessToken)
        {
            $securedPat = (ConvertTo-SecureString -String $PersonalAccessToken -AsPlainText -Force)
            $_session | Add-Member -NotePropertyName 'PersonalAccessToken' -NotePropertyValue $securedPat
        }
        If ($Credential)
        {
            $_session | Add-Member -NotePropertyName 'Credential' -NotePropertyValue $Credential
        }
        If ($Proxy)
        {
            $_session | Add-Member -NotePropertyName 'Proxy' -NotePropertyValue $Proxy            
        }
        If ($ProxyCredential)
        {
            $_session | Add-Member -NotePropertyName 'ProxyCredential' -NotePropertyValue $ProxyCredential
        }
        If ($null -eq $Global:_APSessions)
        {
            $Global:_APSessions = @()
        }
        $Global:_APSessions += $_session
        Return $_session
    }
}

# Publish-APBuildDefinition.ps1
function Publish-APBuildDefinition
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipelines build definition.
 
    .DESCRIPTION
 
    Creates an Azure Pipelines build definition by a template.
    A template can be retrieved by Get-APBuildDefinition.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DefinitionToCloneId
 
    Undefinied, see link for documentation.
 
    .PARAMETER DefinitionToCloneRevision
 
    Undefinied, see link for documentation.
 
    .PARAMETER ValidateProcessOnly
 
    Undefinied, see link for documentation.
 
    .PARAMETER Template
 
    The template provided by Get-APBuildDefinition.
 
    .INPUTS
         
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, Azure Pipelines build.
 
    .EXAMPLE
 
    Creates AP build definition from the $template provided. $template is a JSON representation of the definition that can be found in the history of the release deinifiton during editing.
 
    Publish-APBuildDefinition -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DefinitionObject $template
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/definitions/create?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter()]
        [int]
        $DefinitionToCloneId,

        [Parameter()]
        [int]
        $DefinitionToCloneRevision,

        [Parameter()]
        [bool]
        $ValidateProcessOnly,

        [Parameter(Mandatory)]
        [PSobject]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = Get-APApiEndpoint -ApiType 'build-definitions'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        Else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Publish-APReleaseDefinition.ps1
function Publish-APReleaseDefinition
{
    <#
    .SYNOPSIS
 
    Creates an Azure Pipelines release definition.
 
    .DESCRIPTION
 
    Creates an Azure Pipelines release definition by using a template.
    The template can be retrieved by using Get-APReleaseDefinition.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    The template provided by Get-APReleaseDefinition.
 
    .INPUTS
         
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, Azure Pipelines build.
 
    .EXAMPLE
 
    Creates AP release definition from the $template provided. $template is a JSON representation of the definition that can be found in the history of the release deinifiton during editing.
 
    Publish-APReleaseDefinition -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DefinitionObject $template
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/definitions/create?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [PSobject]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = Get-APApiEndpoint -ApiType 'release-definitions'
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Register-APPSRepository.ps1
function Register-APPSRepository
{
    <#
    .SYNOPSIS
 
    Registers a PSRepository to an Azure DevOps feed.
 
    .DESCRIPTION
 
    Registers a PSRepository to an Azure DevOps feed.
    A list of feeds can be retrieved with Get-APFeedList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedName
 
    The name of the feed to register.
 
    .PARAMETER RepositoryName
 
    The name of the PSRepository.
 
    .PARAMETER InstallationPolicy
 
    Specifies the installation policy. Valid values are: Trusted, UnTrusted. The default value is Trusted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines feed.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/feed/feeds/queue?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $FeedName,

        [Parameter(Mandatory)]
        [string]
        $RepositoryName,

        [Parameter()]
        [ValidateSet('Trusted', 'UnTrusted')]
        [string]
        $InstallationPolicy = 'Trusted'
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $getAPFeedListSplat = @{
            Collection = $Collection
            Instance   = $Instance
            ApiVersion = $ApiVersion
        }
        If ($Credential)
        {
            $getAPFeedListSplat.Credential = $Credential
        }
        If ($PersonalAccessToken)
        {
            $getAPFeedListSplat.PersonalAccessToken = $PersonalAccessToken
        }
        If ($Proxy)
        {
            $getAPFeedListSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $getAPFeedListSplat.ProxyCredential = $ProxyCredential
        }
        $feedListObject = Get-APFeedList @getAPFeedListSplat | Where-Object { $PSItem.Name -eq $FeedName }
        If ($feedListObject)
        {
            $apiEndpoint = (Get-APApiEndpoint -ApiType 'packaging-feedName') -f $FeedName
            $setAPUriSplat = @{
                Collection  = $Collection
                Instance    = $Instance
                Project     = $Project
                ApiVersion  = $ApiVersion
                ApiEndpoint = $apiEndpoint
                Query       = $queryParameters
            }
            [uri] $uri = Set-APUri @setAPUriSplat
        }
        else
        {
            Write-Error "[$($MyInvocation.MyCommand.Name)]: Unable to locate a feed with the name of [$FeedName]"
        }
        If ($uri)
        {
            $registerPSRepositorySplat = @{
                Name               = $RepositoryName
                PublishLocation    = $uri
                SourceLocation     = $uri
                InstallationPolicy = $InstallationPolicy
            }
            If ($Proxy)
            {
                $registerPSRepositorySplat.Proxy = $Proxy
            }
            If ($ProxyCredential)
            {
                $registerPSRepositorySplat.ProxyCredential = $ProxyCredential
            }
            Register-PSRepository @registerPSRepositorySplat
        }
    }
    
    end
    {
    }
}
# Remove-APBuild.ps1
function Remove-APBuild
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline build.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline build by build id.
    The id can be retrieved by using Get-APBuildList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER BuildId
     
    The id of the build to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APBuild does not generate any output.
 
    .EXAMPLE
 
    Deletes AP build with the id of '5'.
 
    Remove-APBuild -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -BuildId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/delete?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [int]
        $BuildId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'build-buildId') -f $BuildId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APBuildDefinition.ps1
function Remove-APBuildDefinition
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline build definition.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline build definition by definition id.
    The id can be retrieved by using Get-APBuildDefinitionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DefinitionId
     
    The ID of the definition to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APBuildDefinition does not generate any output.
 
    .EXAMPLE
 
    Deletes AP build definition with the id of '5'.
 
    Remove-APBuildDefinition -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DefinitionId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/definitions/delete?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [int]
        $DefinitionId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'build-definitionId') -f $DefinitionId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APDashboard.ps1
function Remove-APDashboard
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline dashboard.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline dashboard by dashboard id.
    The id can be retrieved by using Get-APDashboardList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DashboardId
     
    The ID of the dashboard to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APDashboard does not generate any output.
 
    .EXAMPLE
 
    Deletes AP dashboard with the id of '5'.
 
    Remove-APDashboard -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DashboardId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/dashboard/dashboards/delete?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [string]
        $DashboardId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'dashboard-dashboardId') -f $DashboardId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APDeploymentGroup.ps1
function Remove-APDeploymentGroup
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline deployment group.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline deployment group by deployment group id.
    The id can be retrieved by using Get-APDeploymentGroupList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DeploymentGroupId
     
    ID of the deployment group to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APDeploymentGroup does not generate any output.
 
    .EXAMPLE
 
    Deletes AP deployment group with the deployment group id of '6'.
 
    Remove-APDeploymentGroup -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DeploymentGroupID 6
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/deploymentgroups/delete?view=vsts-rest-5.0#
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [int]
        $DeploymentGroupId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-deploymentGroupId') -f $DeploymentGroupID
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APFeed.ps1
function Remove-APFeed
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline feed.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline feed and all it's packages, by feed id.
    The id can be retrieved by using Get-APFeedList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
    For Azure DevOps the value should be https://dev.azure.com/.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedId
     
    The id of the feed to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, does not support output.
 
    .EXAMPLE
 
    Deletes AP feed with the id of '5'.
 
    Remove-APFeed -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -FeedId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/feed%20%20management/delete%20feed?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [string]
        $FeedId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'feed-feedId') -f $FeedId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        Invoke-APRestMethod @invokeAPRestMethodSplat 
    }
    
    end
    {
    }
}
# Remove-APGitFile.ps1
function Remove-APGitFile
{
    <#
    .SYNOPSIS
 
    Removes an Azure Pipeline Git file.
 
    .DESCRIPTION
 
    Removes an Azure Pipeline Git file based on the repository id the branch name and the branch object id.
    The repository id can be retrieved by using Get-APRepositoryList.
    The branch name and object id can be retrieved by using Get-APGitRefList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER RepositoryId
 
    The name or ID of the repository.
 
    .PARAMETER ObjectId
 
    The branch object id to remove the file from. Use Get-APGitRefList to identify the object id.
 
    .PARAMETER BranchName
 
    The name of the branch to remove the file from.
 
    .PARAMETER Path
 
    The path to the file relative to the root of the repository.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines Git ref.
 
    .EXAMPLE
 
    Removes a file at '/images/people/default.jpg' from the repository named 'myRepository'.
 
    Remove-APGitFile -Session 'mySession' -BranchName 'myBranchName' -ObjectId '50114dacf4ed256f37e397ded65188400d84b0831bd' -Path '/images/people/default.jpg'
     
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest-5.0#delete_a_file
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $RepositoryId, 

        [Parameter(Mandatory)]
        [string]
        $ObjectId, 

        [Parameter(Mandatory)]
        [string]
        $BranchName,
        
        [Parameter(Mandatory)]
        [string]
        $Path
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $body = @{
            refUpdates = @(
                @{
                    name        = $BranchName
                    oldObjectId = $ObjectId
                }
            )
            commits    = @(
                @{
                    comment = "Removed file from $Path"
                    changes = @(
                        @{
                            changeType = 'delete'
                            item       = @{
                                path = $Path
                            }
                        }
                    )
                }
            )
        }

        $apiEndpoint = (Get-APApiEndpoint -ApiType 'git-pushes') -f $RepositoryId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APNotificationSubscription.ps1
function Remove-APNotificationSubscription
{
    <#
    .SYNOPSIS
 
    Deletes a notification subscription by its id.
 
    .DESCRIPTION
 
    Deletes a notification subscription by its id.
    The id can be retrieved with Get-APSubscriptionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER SubscriptionId
 
    The id of the subscription.
 
    .PARAMETER QueryFlags
 
    Undocumented.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines subscription list.
 
    .EXAMPLE
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/notification/subscriptions/delete?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [string]
        $SubscriptionId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
        
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'notification-subscriptionId') -f $SubscriptionId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $null = Invoke-APRestMethod @invokeAPRestMethodSplat 
    }
    
    end
    {
    }
}
# Remove-APNugetPackageVersion.ps1
function Remove-APNugetPackageVersion
{
    <#
    .SYNOPSIS
 
    Removes an Azure Pipeline nuget package version from the feed and places it in the recycle bin.
 
    .DESCRIPTION
 
    Removes an Azure Pipeline nuget package version from the feed and places it in the recycle bin by feed id, package name, and package version.
    The id can be retrieved by using Get-APFeedList.
    The package name and version can be retrieved by using Get-APPackageList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
    For Azure DevOps the value should be https://dev.azure.com/.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedId
     
    The id of the feed to be deleted.
 
    .PARAMETER PackageName
 
    The name of the package to be deleted.
 
    .PARAMETER PackageVersion
 
    The version of the package to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    Azure Pipelines Package, the package object that was sent to the recyle bin.
 
    .EXAMPLE
 
    Deletes AP feed with the id of '5'.
 
    Remove-APNugetPackageVersion -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -FeedId 5 -PackageName 'myPackage' -PackageVersion 'myPackageVersion'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifactspackagetypes/nuget/delete%20package%20version?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [string]
        $FeedId,
        
        [Parameter(Mandatory)]
        [string]
        $PackageName,

        [Parameter(Mandatory)]
        [string]
        $PackageVersion
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'feed-packageVersion') -f $FeedId, $PackageName, $PackageVersion
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        Invoke-APRestMethod @invokeAPRestMethodSplat 
    }
    
    end
    {
    }
}
# Remove-APNugetPackageVersionFromRecycleBin.ps1
function Remove-APNugetPackageVersionFromRecycleBin
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline nuget package version from the recyle bin.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline nuget package version from the recycle bin by feed id, package name, and package version.
    The id can be retrieved by using Get-APFeedList.
    The package name and version can be retrieved by using Get-APPackageList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
    For Azure DevOps the value should be https://dev.azure.com/.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER FeedId
     
    The id of the feed to be deleted.
 
    .PARAMETER PackageName
 
    The name of the package to be deleted.
 
    .PARAMETER PackageVersion
 
    The version of the package to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APNugetPackageVersionFromRecycleBin does not support output.
 
    .EXAMPLE
 
    Deletes AP feed with the id of '5' from the recycle bin.
 
    Remove-APNugetPackageVersionFromRecycleBin -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -FeedId 5 -PackageName 'myPackage' -PackageVersion 'myPackageVersion'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/artifactspackagetypes/nuget/delete%20package%20version%20from%20recycle%20bin?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [string]
        $FeedId,
        
        [Parameter(Mandatory)]
        [string]
        $PackageName,

        [Parameter(Mandatory)]
        [string]
        $PackageVersion
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'feed-RBpackageVersion') -f $FeedId, $PackageName, $PackageVersion
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        Invoke-APRestMethod @invokeAPRestMethodSplat 
    }
    
    end
    {
    }
}
# Remove-APPolicyConfiguration.ps1
function Remove-APPolicyConfiguration
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline policy configuration.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline policy configuration by configuration id.
    The id can be retrieved by using Get-APPolicyConfigurationList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ConfigurationId
     
    The id of the policy configuration to remove.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, does not support output.
 
    .EXAMPLE
 
    Deletes AP policy configuration with the id of '5'.
 
    Remove-APPolicyConfiguration -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ConfigurationId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations/delete?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [int]
        $ConfigurationId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'policy-configurationId') -f $ConfigurationId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $null = Invoke-APRestMethod @invokeAPRestMethodSplat 
    }
    
    end
    {
    }
}
# Remove-APRelease.ps1
function Remove-APRelease
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline release.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline release by release id.
    The id can be retrieved by using Get-APReleaseList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ReleaseId
     
    The ID of the release to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APRelease does not generate any output.
 
    .EXAMPLE
 
    Deletes AP release with the id of '5'.
 
    Remove-APRelease -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 5
 
    .LINK
 
    Undocumented
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [int]
        $ReleaseId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-releaseId') -f $ReleaseId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APReleaseDefinition.ps1
function Remove-APReleaseDefinition
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline release definition.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline release definition by definition id.
    The id can be retrieved by using Get-APReleaseDefinitionList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DefinitionId
     
    The ID of the definition to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APReleaseDefinition does not generate any output.
 
    .EXAMPLE
 
    Deletes AP release definition with the definition id of '5'.
 
    Remove-APReleaseDefinition -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DefinitionId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/release/definitions/delete?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $DefinitionId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-definitionId') -f $DefinitionId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APServiceEndpoint.ps1
function Remove-APServiceEndpoint
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline service endpoint.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline service endpoint by service endpoint id.
    The id can be retrieved by using Get-APServiceEndpointList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER EndpointId
     
    The id of the service endpoint to be deleted.
 
    .PARAMETER Deep
     
    Specific to AzureRM endpoint created in Automatic flow. When set to true, this will also delete corresponding AAD application in Azure. Default value is true.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, does not generate any output.
 
    .EXAMPLE
 
    Deletes AP service endpoint with the id of '5'.
 
    Remove-APServiceEndpoint -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -EndpointId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/delete?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
                
        [Parameter(Mandatory)]
        [string]
        $EndpointId,

        [Parameter()]
        [bool]
        $Deep
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'serviceendpoint-endpointId') -f $EndpointId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APSession.ps1
Function Remove-APSession
{
    <#
    .SYNOPSIS
 
    Removes an Azure Pipelines PS session.
 
    .DESCRIPTION
 
    Removes an Azure Pipelines PS session.
    If the session is saved, it will be removed from the saved sessions as well.
 
    .PARAMETER Id
     
    Session id.
 
    .PARAMETER Path
     
    The path where session data will be stored, defaults to $Script:ModuleDataPath.
 
    .LINK
 
    Save-APSession
    Remove-APSession
 
    .INPUTS
 
    PSObject. Get-APSession
 
    .OUTPUTS
 
    PSObject. Remove-APSession returns a PSObject that contains the following:
        Instance
        Collection
        PersonalAccessToken
 
    .EXAMPLE
 
    Deletes AP session with the id of '2'.
 
    Remove-APSession -Id 2
 
    .EXAMPLE
 
    Deletes all AP sessions in memory and stored on disk.
 
    Remove-APSession
 
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory,
            ValueFromPipelineByPropertyName)]
        [int]
        $Id,
       
        [Parameter()]
        [string]
        $Path = $Script:ModuleDataPath  
    )
    Process
    {
        $sessions = Get-APSession -Id $Id
        Foreach ($session in $sessions)
        {
            If ($session.Saved -eq $true)
            {
                $newData = @{SessionData = @() }
                $data = Get-Content -Path $Path -Raw | ConvertFrom-Json
                Foreach ($_data in $data.SessionData)
                {
                    If ($_data.Id -eq $session.Id)
                    {
                        Continue
                    }       
                    else
                    {
                        $newData.SessionData += $_data
                    }
                }
                $newData | ConvertTo-Json -Depth 5 | Out-File -FilePath $Path
            }
            $Global:_APSessions = $Global:_APSessions | Where-Object { $PSItem.Id -ne $session.Id }
        }
    }
}
# Remove-APTarget.ps1
function Remove-APTarget
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline deployment group target.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline deployment group target by the deployment group id and the target id.
    The deployment group id can be retrieved by using Get-APDeploymentGroupList.
    The target id can be retrieved by using Get-APTargetList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DeploymentGroupId
     
    ID of the deployment group in which deployment target is deleted.
 
    .PARAMETER TargetId
     
    ID of the deployment target to delete.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APTarget does not generate any output.
 
    .EXAMPLE
 
    Deletes AP target with the deployment group id of '6' and the target id of '25'.
 
    Remove-APTarget -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DeploymentGroupID 6 -TargetId 25
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/targets/delete?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $DeploymentGroupId,

        [Parameter(Mandatory)]
        [int]
        $TargetId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-targetId') -f $DeploymentGroupID, $TargetId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Remove-APVariableGroup.ps1
function Remove-APVariableGroup
{
    <#
    .SYNOPSIS
 
    Deletes an Azure Pipeline variable group.
 
    .DESCRIPTION
 
    Deletes an Azure Pipeline variable group by group id.
    The id can be retrieved by using Get-APVariableGroupList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER GroupId
     
    The ID of the Group to be deleted.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Remove-APVariableGroup does not generate any output.
 
    .EXAMPLE
 
    Deletes AP variable group with the group id of '5'.
 
    Remove-APVariableGroup -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -GroupId 5
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/Variable/Groups/delete?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $GroupId
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-variablegroupId') -f $GroupId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'DELETE'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Save-APSession.ps1
Function Save-APSession
{
    <#
    .SYNOPSIS
 
    Saves an Azure Pipelines PS session to disk.
 
    .DESCRIPTION
 
    Saves an Azure Pipelines PS session to disk.
    The sensetive data is encrypted and stored in the users local application data.
    These saved sessions will be available next time the module is imported.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Path
     
    The path where session data will be stored, defaults to $Script:ModuleDataPath.
 
    .PARAMETER PassThru
     
    Returns the saved session object.
     
    .INPUTS
 
    PSbject. Get-APSession, New-APSession
 
    .OUTPUTS
 
    None. Save-APSession does not generate any output.
 
    .EXAMPLE
     
    Creates a session with the name of 'myFirstSession' and saves it to disk.
 
    $newAPSession = @{
        Collection = 'myCollection'
        Project = 'myFirstProject'
        Instance = 'https://dev.azure.com/'
        PersonalAccessToken = 'myToken'
        Version = 'vNext'
        SessionName = 'myFirstSession'
    }
    New-APSession @newAPSession | Save-APSession
    #>


    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory,
            ValueFromPipeline)]
        [object]
        $Session,
       
        [Parameter()]
        [string]
        $Path = $Script:ModuleDataPath
    )
    Begin
    {
        If (-not(Test-Path $Path))
        {
            $data = @{SessionData = @() }
        }
        else 
        {
            $data = Get-Content -Path $Path -Raw | ConvertFrom-Json           
        }
    }
    Process
    {
        If ($data.SessionData.Id -notcontains $session.Id)
        {
            $_object = @{
                Version     = $Session.Version
                ApiVersion  = $Session.ApiVersion
                Instance    = $Session.Instance
                Id          = $Session.Id
                SessionName = $Session.SessionName
                Collection  = $Session.Collection
                Project     = $Session.Project
                Saved       = $true
            }
            If ($Session.PersonalAccessToken)
            {
                $_object.PersonalAccessToken = ($Session.PersonalAccessToken | ConvertFrom-SecureString) 
            }
            If ($Session.Credential)
            {
                $_credentialObject = @{
                    Username = $Session.Credential.UserName
                    Password = ($Session.Credential.GetNetworkCredential().SecurePassword | ConvertFrom-SecureString)
                }
                $_object.Credential = $_credentialObject
            }
            If ($Session.Proxy)
            {
                $_object.Proxy = $Session.Proxy
            }
            If ($Session.ProxyCredential)
            {
                $_proxyCredentialObject = @{
                    Username = $Session.ProxyCredential.UserName
                    Password = ($Session.ProxyCredential.GetNetworkCredential().SecurePassword | ConvertFrom-SecureString)
                }
                $_object.ProxyCredential = $_proxyCredentialObject
            }
            $data.SessionData += $_object
            $session | Remove-APSession -Path $Path
        }
    }
    End
    {
        $data | ConvertTo-Json -Depth 5 | Out-File -FilePath $Path
        Write-Verbose "[$($MyInvocation.MyCommand.Name)]: [$SessionName]: Session data has been stored at [$Path]"
    }
}

# Set-APBuildNumber.ps1
function Set-APBuildNumber
{
    <#
    .SYNOPSIS
 
    Pipeline invocation command used to update build number for current build.
 
    .DESCRIPTION
 
    Pipeline invocation command used to update build number for current build.
    Pipeline invocation commands make changes during pipeline execution. If the command is excuted in a console window the command will output logging messages.
 
    .PARAMETER BuildNumber
 
    The new build number.
 
    .INPUTS
 
    None, does not support the pipline.
 
    .OUTPUTS
 
    VSO build number.
 
    .EXAMPLE
 
    Set-APBuildNumber -BuildNumber '1.0.0'
 
    #>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        [string]
        $BuildNumber
    )
    begin
    {
        If ($env:Build_BuildId -or $env:Release_DefinitionId)
        {
            $pipelineInvocation = $true
        }
    }
    process
    {
        If ($pipelineInvocation)
        {
            Write-Host "##vso[build.updatebuildnumber]$BuildNumber"
        }
        else
        {
            Write-Verbose -Message "[$($MyInvocation.MyCommand.Name)]: Updated build number to: [$BuildNumber]"
        }
    }
    end
    {

    }
}
# Set-APReleaseName.ps1
function Set-APReleaseName
{
    <#
    .SYNOPSIS
 
    Pipeline invocation command used to update the release name for the current release.
 
    .DESCRIPTION
 
    Pipeline invocation command used to update the release name for the current release
    Pipeline invocation commands make changes during pipeline execution. If the command is excuted in a console window the command will output logging messages.
 
    .PARAMETER ReleaseName
 
    The new release name.
 
    .INPUTS
 
    None, does not support the pipline.
 
    .OUTPUTS
 
    VSO release name.
 
    .EXAMPLE
 
    Set-APReleaseName -ReleaseName 'My New Release Name'
 
    #>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        [string]
        $ReleaseName
    )
    begin
    {
        If ($env:Build_BuildId -or $env:Release_DefinitionId)
        {
            $pipelineInvocation = $true
        }
    }
    process
    {
        If ($pipelineInvocation)
        {
            Write-Host "##vso[release.updatereleasename]$ReleaseName"
        }
        else
        {
            Write-Verbose -Message "[$($MyInvocation.MyCommand.Name)]: Updated release name to: [$ReleaseName]"
        }
    }
    end
    {

    }
}
# Set-APTaskResult.ps1
function Set-APTaskResult
{
    <#
    .SYNOPSIS
 
    Pipeline invocation command used to set the finish timeline record for current task, set task result and current operation.
 
    .DESCRIPTION
 
    Pipeline invocation command used to set the finish timeline record for current task, set task result and current operation.
    Pipeline invocation commands make changes during pipeline execution. If the command is excuted in a console window the command will output logging messages.
 
    .PARAMETER Message
 
    The log message.
 
    .PARAMETER Result
 
    The result of the task, defaults to Succeeded.
 
    .INPUTS
 
    None, does not support the pipline.
 
    .OUTPUTS
 
    Task result.
 
    .EXAMPLE
 
    Set-TaskResult -Message 'Done' -Result 'Succeeded'
 
    #>

    [CmdletBinding()]
    param
    (
        [Parameter()]
        [string]
        $Message,

        [Parameter()]
        [ValidateSet('Succeeded', 'SucceededWithIssues', 'Failed', 'Canceled', 'Skipped')]
        [string]
        $Result = 'Succeeded'
    )
    begin
    {
        If ($env:Build_BuildId -or $env:Release_DefinitionId)
        {
            $pipelineInvocation = $true
        }
    }
    process
    {
        If ($pipelineInvocation)
        {
            Write-Host "##vso[task.complete result=$Result;]$Message"
        }
        else
        {
            Write-Verbose -Message "[$($MyInvocation.MyCommand.Name)]: Result: [$Result], Message: [$Message]"
        }
    }
    end
    {

    }
}
# Set-APVariable.ps1
function Set-APVariable
{
    <#
    .SYNOPSIS
 
    Pipeline invocation command used to sets a variable in the variable service of taskcontext.
 
    .DESCRIPTION
 
    Pipeline invocation command used to sets a variable in the variable service of taskcontext.
    The first task can set a variable, and following tasks in the same phase are able to use the variable.
    Pipeline invocation commands make changes during pipeline execution. If the command is excuted in a console window the command will output logging messages.
 
    .PARAMETER Name
 
    The name of the variable to set.
 
    .PARAMETER Value
 
    The value of the variable.
 
    .PARAMETER IsSecret
 
    Sets the variable to a secret.
    When issecret is set to true, the value of the variable will be saved as secret and masked out from log.
    Secret variables are not passed into tasks as environment variables and must be passed as inputs.
 
    .INPUTS
 
    None, does not support the pipline.
 
    .OUTPUTS
 
    VSO release name.
 
    .EXAMPLE
 
    Set-APReleaseName -ReleaseName 'My New Release Name'
 
    #>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        [string]
        $Name, 

        [Parameter(Mandatory)]
        [string]
        $Value, 

        [Parameter()]
        [switch]
        $IsSecret
    )
    begin
    {
        If ($env:Build_BuildId -or $env:Release_DefinitionId)
        {
            $pipelineInvocation = $true
        }
    }
    process
    {
        If ($pipelineInvocation)
        {
            If ($IsSecret.IsPresent)
            {
                Write-Host "##vso[task.setvariable variable=$Name;issecret=true]$Value"
            }
            else
            {
                Write-Host "##vso[task.setvariable variable=$Name]$Value"
            }
        }
        else
        {
            If ($IsSecret.IsPresent)
            {
                Write-Verbose -Message "[$($MyInvocation.MyCommand.Name)]: Updated the variable [$Name] to the value of [*****]"                
            }
            else
            {
                Write-Verbose -Message "[$($MyInvocation.MyCommand.Name)]: Updated the variable [$Name] to the value of [$Value]"                
            }
        }
    }
    end
    {

    }
}
# Update-APApproval.ps1
function Update-ApApproval
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline approval.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline deployment approval by approval id.
    The approval id can be retrieved by using Get-APApprovalList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ApprovalId
     
    Id of the approval.
 
    .PARAMETER Status
     
    The status for the updated approval.
 
    .PARAMETER Comment
     
    The comment for the updated approval.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, An Azure Pipelines approval.
 
    .EXAMPLE
 
    Updates AP approval with the approval id of '6' to the status of 'appoved'.
 
    Update-APApproval -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ApprovalId 6 -Status 'approved'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/approvals/update?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $ApprovalId,

        [Parameter(Mandatory)]
        [ValidateSet('approved', 'canceled', 'pending', 'reassigned', 'rejected', 'skipped', 'undefined')]
        [string]
        $Status,

        [Parameter()]
        [string]
        $Comment
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = @{
            status = $Status
        }
        If ($Comment)
        {
            $body.comment = $Comment
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-approvalId') -f $ApprovalId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'PATCH'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Update-APBuild.ps1
function Update-APBuild
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline build.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline build by a template.
    A template can retrived by using Get-APBuild.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    The template provided by Get-APBuild.
 
    .INPUTS
         
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, Azure Pipelines build.
 
    .EXAMPLE
 
    Updates AP build definition to the $template. $template is a JSON representation of the build.
 
    Update-APBuild -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -Template $template
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/update%20build?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [PSobject]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'build-buildId') -f $body.Id
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'PATCH'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Update-APBuildDefinition.ps1
function Update-APBuildDefinition
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline build definition.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline build definition by a template.
    A template can retrived by using Get-APBuildDefinition.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    The template provided by Get-APBuildDefinition.
 
    .INPUTS
         
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, Azure Pipelines build.
 
    .EXAMPLE
 
    Updates AP build definition to the $template. $template is a JSON representation of the definition that can be found in the history of the release deinifiton during editing.
 
    Update-APBuildDefinition -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -Template $template
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/Build/definitions/update?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [PSobject]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'build-definitionId') -f $body.Id
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'PUT'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Update-APDeploymentGroup.ps1
function Update-APDeploymentGroup
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline deployment group.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline deployment group by deployment group id.
    The id can be retrieved by using Get-APDeploymentGroupList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DeploymentGroupId
     
    ID of the deployment.
 
    .PARAMETER Description
     
    Description of the deployment group.
  
    .PARAMETER Name
     
    Name of the deployment group.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, An Azure Pipelines deployment group.
 
    .EXAMPLE
 
    Updates AP deployment group's name with the deployment group id of '6' to 'myGroupsNewName'.
 
    Update-APDeploymentGroup -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DeploymentGroupID 6 -Name 'myGroupsNewName'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/distributedtask/deploymentgroups/update?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $DeploymentGroupId,

        [Parameter()]
        [string]
        $Name,

        [Parameter()]
        [string]
        $Description
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = @{
            Name        = $Name
            Description = $Description
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-deploymentGroupId') -f $DeploymentGroupID
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'PATCH'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Update-APInstalledExtension.ps1
function Update-APInstalledExtension
{
    <#
    .SYNOPSIS
 
    Updates an installed extension.
 
    .DESCRIPTION
 
    Updates an installed extension.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ExtensionObject
 
    Azure Devops installed extension object, provided by Get-APInstalledExtensionList.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines extension.
 
    .EXAMPLE
 
    Updates the installed extension for 'WindowsServiceManagerWindowsServiceManager'.
 
    $myExtensionObject = Get-APInstalledExtension -Session 'mySession' -PublisherName 'MDSolutions' -ExtensionName 'WindowsServiceManagerWindowsServiceManager'
    Update-APInstalledExtension -Session 'mySession' -ExtensionObject $myExtensionObject
 
    .LINK
 
    Windows Service Manager extension:
    https://marketplace.visualstudio.com/items?itemName=MDSolutions.WindowsServiceManagerWindowsServiceManager
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/extensionmanagement/installed%20extensions/update?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [object]
        $ExtensionObject
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $apiEndpoint = Get-APApiEndpoint -ApiType 'extensionmanagement-installedextensions'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Method              = 'PATCH'
            Body                = $ExtensionObject
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Update-APPolicyConfiguration.ps1
function Update-APPolicyConfiguration
{
    <#
    .SYNOPSIS
 
    Updates a Azure Pipeline policy configuration.
 
    .DESCRIPTION
 
    Updates a Azure Pipeline policy configuration by configuration id.
    The id can be retrieved by using Get-APPolicyConfigurationList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    A policy template. A modified configuration policy object.
    The policy object can be retrived with Get-APPolicyConfigurationList.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines policy configuration(s)
 
    .EXAMPLE
 
    Updates a policy configuration's 'isDeleted' value to false
    Update-APPolicyConfiguration -Session $Session -Template $template
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations/update?view=azure-devops-rest-5.1
 
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [object]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = Get-APApiEndpoint -ApiType 'policy-configurations'
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'POST'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Update-APRelease.ps1
function Update-APRelease
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline release.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline release by release id.
    The id can be retrieved by using Get-APreleaseList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    The template provided by Get-APRelease.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Update-APRelease returns Azure Pipelines release definition.
 
    .EXAMPLE
 
    Updates AP release with the release id of '5' with the $template.
 
    Update-APRelease -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 5 -Template $template
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/update%20release?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [PSobject]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-releaseId') -f $body.Id
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'PUT'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Update-APReleaseDefinition.ps1
function Update-APReleaseDefinition
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline release definition.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline release definition by a template.
    A template can retrived by using Get-APReleaseDefinition.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    The template provided by Get-APReleaseDefinition.
 
    .INPUTS
         
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, Azure Pipelines build.
 
    .EXAMPLE
 
    Updates AP release definition with the $template. $template is a JSON representation of the definition that can be found in the history of the release deinifiton during editing.
 
    Update-APReleaseDefinition -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -Template $template
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/release/definitions/update?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [PSobject]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-definitionId') -f $body.Id
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'PUT'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Update-APReleaseEnvironment.ps1
function Update-APReleaseEnvironment
{
    <#
    .SYNOPSIS
 
    Update the status of a release environment.
 
    .DESCRIPTION
 
    Update the status of a release environment by release id and environment id
    The release id can be retrieved by using Get-APReleaseList.
    The environment id can be retrieved by using Get-APRelease and providing the release id.
    The environment id is nested in the release object that is returned.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ReleaseID
     
    Id of the release.
 
    .PARAMETER EnvironmentID
     
    Id of the release environment.
 
    .PARAMETER Comment
     
    Comment used for the release status change.
     
    .PARAMETER ScheduledDeploymentTime
     
    Scheduled deployment time.
     
    .PARAMETER Status
     
    Environment status.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Release Environment
 
    .EXAMPLE
 
    Updates AP release environment with the release id of '3' and the environment id of '8099' to the status of 'inProgress'.
 
    Update-APReleaseEnvironment -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 3 -EnvironmentId 8099 -Status 'inProgress'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/release/releases/update%20release%20environment?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $ReleaseId,

        [Parameter(Mandatory)]
        [int]
        $EnvironmentId,

        [Parameter()]
        [string]
        $Comment, 

        [Parameter()]
        [string]
        $ScheduledDeploymentTime,

        [Parameter(Mandatory)]
        [string]
        [ValidateSet('canceled', 'inProgress', 'notStarted', 'partiallySucceeded', 'queued', 'rejected', 'scheduled', 'succeeded', 'undefined')]
        $Status
    )

    
    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = @{
            status = $Status
        }
        if ($Comment)
        {
            $body.comment = $Comment
        }
        If ($ScheduledDeploymentTime)
        {
            $body.scheduledDeploymentTime = $ScheduledDeploymentTime
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-environmentId') -f $ReleaseId, $EnvironmentId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Method              = 'PATCH'
            Body                = $body
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        Invoke-APRestMethod @invokeAPRestMethodSplat
    }
    
    end
    {
    }
}
# Update-APReleaseResource.ps1
function Update-APReleaseResource
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline release resources.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline release resources by release id.
    The id can be retrieved by using Get-APreleaseList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ReleaseId
 
    The id of the release to ne modified.
 
    .PARAMETER Comment
 
    Sets comment for release.
 
    .PARAMETER KeepForever
 
    Set 'true' to exclude the release from retention policies.
 
    .PARAMETER ManualEnvironments
 
    Sets list of manual environments.
 
    .PARAMETER Status
 
    Sets status of the release.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    None, Update-APReleaseResource returns Azure Pipelines release definition.
 
    .EXAMPLE
 
    Updates AP release resource with the release id of '5' with the comment of 'This is completed'.
 
    Update-APReleaseResource -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 5 -Comment 'This is completed'
 
    .EXAMPLE
 
    Updates AP release resource with the release id of '5' with the stauts of 'abandoned'.
 
    Update-APReleaseResource -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 5 -Status 'abandoned'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/update%20release%20resource?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [string]
        $ReleaseId,

        [Parameter()]
        [string]
        $Comment,
        
        [Parameter()]
        [bool]
        $KeepForever,
        
        [Parameter()]
        [string[]]
        $ManualEnvironments,
        
        [Parameter()]
        [ValidateSet('abandoned', 'active', 'draft', 'undefined')]
        [string]
        $Status
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = @{ }
        If ($PSBoundParameters.Keys -contains 'Comment')
        {
            $body.comment = $Comment
        }
        If ($PSBoundParameters.Keys -contains 'KeepForever')        
        {
            $body.KeepForever = $KeepForever
        }
        If ($PSBoundParameters.Keys -contains 'ManualEnvironments')        
        {
            $body.ManualEnvironments = $ManualEnvironments
        }
        If ($PSBoundParameters.Keys -contains 'Status')        
        {
            $body.Status = $Status
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'release-releaseId') -f $ReleaseId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            ContentType         = 'application/json'
            Body                = $body
            Method              = 'PATCH'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.count -eq 0)
        {
            Return
        }
        ElseIf ($results.value)
        {
            Return $results.value
        }
        Else
        {
            Return $results
        }
    }
    
    end
    {
    }
}
# Update-APServiceEndpoint.ps1
function Update-APServiceEndpoint
{
    <#
    .SYNOPSIS
 
    Updates an Azure Pipeline service endpoint.
 
    .DESCRIPTION
 
    Updates an Azure Pipeline service endpoint by endpoint id.
    The id can be retrieved by using Get-APServiceEndpointList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Template
 
    A service endpoint template. A modified service endpoint type object.
    The service endpoint type can be retrived with Get-APServiceEndpointTypeList.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines service endpoint(s)
 
    .EXAMPLE
 
    Updates the description for the endpoint named 'myNewJenkinsEndpoint'. The password is required in order to update this service type because it does not get returned with Get-APServiceEndpointName.
     
    $session = 'mySession'
    $endpoint = Get-APServiceEndpointName -Session $session -EndpointNames 'myNewJenkinsEndpoint'
    $endpoint.Description = 'Updated description'
    $endpoint.authorization.parameters | Add-Member -NotePropertyName 'password' -NotePropertyValue 'mypassword'
    Update-APServiceEndpoint -Session $session -Template $endpoint
     
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/update%20service%20endpoint?view=azure-devops-rest-5.1
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [object]
        $Template
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = $Template
        $endpointId = $Template.Id
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'serviceendpoint-endpointId') -f $endpointId
        $queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
            Query       = $queryParameters
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'PUT'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Update-APTarget.ps1
function Update-APTarget
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline deployment group target.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline deployment group target.
    The deployment group id can be retrieved by using Get-APDeploymentGroupList.
    The target id can be retrieved by using Get-APTargetList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER DeploymentGroupId
     
    ID of the deployment.
 
    .PARAMETER Id
     
    Identifier of the deployment target.
  
    .PARAMETER Tags
     
    Tags for the deployment target.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSobject, An Azure Pipelines deployment group target.
 
    .EXAMPLE
 
    Updates AP deployment group target with the deployment group id of '6' and id of '30' with the tags of 'myFirstTag', 'mySecondTag'.
 
    Update-APTarget -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -DeploymentGroupID 6 -Id 30 -Tags 'myFirstTag', 'mySecondTag'
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/targets/update?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,
        
        [Parameter(Mandatory)]
        [int]
        $DeploymentGroupId,

        [Parameter(Mandatory)]
        [int]
        $Id,

        [Parameter(Mandatory)]
        [string[]]
        $Tags
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $body = @{
            Tags = ($Tags -join ',')
            Id   = $Id
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-targets') -f $DeploymentGroupID
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'PATCH'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Update-APVariableGroup.ps1
function Update-APVariableGroup
{
    <#
    .SYNOPSIS
 
    Modifies an Azure Pipeline variable group.
 
    .DESCRIPTION
 
    Modifies an Azure Pipeline variable group by group id.
    The id can be retrieved by using Get-APVariableGroupList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
 
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER GroupId
 
    Id of the variable group.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER Description
     
    Sets description of the variable group.
  
    .PARAMETER Name
     
    Sets name of the variable group.
 
    .PARAMETER Variables
     
    Sets variables contained in the variable group.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines variable group.
 
    .EXAMPLE
 
    $varibales = @{
        Var1 = 'updated val1'
        Var2 = 'updated val2'
        Var3 = 'updated val3'
    }
    $updateAPVariableGroupSplat = @{
        Description = 'my updated variable group'
        Name = 'myUpdatedVariableGroup'
        Variables = $varibales
        Instance = 'https://dev.azure.com'
        Collection = 'myCollection'
        Project = 'myFirstProject'
        GroupId = 2
    }
    Update-APVariableGroup @updateAPVariableGroupSplat
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/distributedtask/variablegroups/update?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $GroupId,

        [Parameter()]
        [string]
        $Name,

        [Parameter()]
        [string]
        $Description,

        [Parameter()]
        [object]
        $Variables
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $getAPVariableGroupSplat = @{
            Collection = $Collection
            Instance   = $Instance
            Project    = $Project
            ApiVersion = $ApiVersion
            GroupId    = $GroupId
        }
        If ($PersonalAccessToken)
        {
            $getAPVariableGroupSplat.PersonalAccessToken = $PersonalAccessToken
        }
        If ($Credential)
        {
            $getAPVariableGroupSplat.Credential = $Credential
        }
        If ($Proxy)
        {
            $getAPVariableGroupSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $getAPVariableGroupSplat.ProxyCredential = $ProxyCredential
        }
        $_groupData = Get-APVariableGroup @getAPVariableGroupSplat

        If ($PSBoundParameters.Keys -contains 'Variables')
        {
            If ($Variables.GetType().Name -eq 'hashtable')
            {
                $_variables = @{ }
                Foreach ($token in $Variables.Keys)
                {
                    $_variables.$token = @{
                        Value = $Variables.$token
                    }
                }
            }
            else 
            {
                $_variables = $Variables    
            }
        }
        else
        {
            $_variables = $_groupData.Variables
        }
        If ($PSBoundParameters.Keys -contains 'Name')
        {
            $_name = $Name
        }
        else
        {
            $_name = $_groupData.Name
        }
        If ($PSBoundParameters.Keys -contains 'Description')
        {
            $_description = $Description
        }
        else
        {
            $_description = $_groupData.Description
        }
        $body = @{
            Name        = $_name
            Type        = $_groupData.Type
            Description = $_description
            Variables   = $_variables
        }
        $apiEndpoint = (Get-APApiEndpoint -ApiType 'distributedtask-VariableGroupId') -f $GroupId
        $setAPUriSplat = @{
            Collection  = $Collection
            Instance    = $Instance
            Project     = $Project
            ApiVersion  = $ApiVersion
            ApiEndpoint = $apiEndpoint
        }
        [uri] $uri = Set-APUri @setAPUriSplat
        $invokeAPRestMethodSplat = @{
            Method              = 'PUT'
            Uri                 = $uri
            Credential          = $Credential
            PersonalAccessToken = $PersonalAccessToken
            Body                = $body
            ContentType         = 'application/json'
            Proxy               = $Proxy
            ProxyCredential     = $ProxyCredential
        }
        $results = Invoke-APRestMethod @invokeAPRestMethodSplat 
        If ($results.value)
        {
            return $results.value
        }
        else
        {
            return $results
        }
    }
    
    end
    {
    }
}
# Wait-APBuild.ps1
function Wait-APBuild
{
    <#
    .SYNOPSIS
 
    Waits for an Azure Pipelines build to exit 'inProgress' status.
 
    .DESCRIPTION
 
    Waits for an Azure Pipelines build to exit 'inProgress' status based on the build id.
    The id can be retrieved by using Get-APBuildList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER BuildId
 
    The ID of the build
 
    .PARAMETER Timeout
     
    Timeout threshold in seconds.
 
    .PARAMETER PollingInterval
     
    The number of seconds to wait before checking the status of the build, defaults to 1.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines build(s)
 
    .EXAMPLE
 
    Waits for the build with the id of '7' for the 'myFirstProject.
 
    Wait-APBuild -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -BuildId 7
 
    .EXAMPLE
 
    Waits for only 30 seconds for the build with the id of '9'.
 
    Wait-APBuild -Session 'mySession' -BuildId 7 -Timeout 30
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/vsts/build/builds/get?view=vsts-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $BuildId,

        [Parameter()]
        [int]
        $Timeout = 300,

        [Parameter()]
        [int]
        $PollingInterval = 1
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $_timeout = (Get-Date).AddSeconds($TimeOut)
        $getAPBuildSplat = @{
            Collection = $Collection
            Instance   = $Instance
            BuildId    = $BuildId
            Project    = $Project
            ApiVersion = $ApiVersion
        }
        If ($PersonalAccessToken)
        {
            $getAPBuildSplat.PersonalAccessToken = $PersonalAccessToken
        }
        If ($Credential)
        {
            $getAPBuildSplat.Credential = $Credential
        }
        If ($Proxy)
        {
            $getAPBuildSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $getAPBuildSplat.ProxyCredential = $ProxyCredential
        }
        Do
        {
            $buildData = Get-APBuild @getAPBuildSplat -ErrorAction 'Stop'
            If ($buildData.Status -eq 'inProgress' -or $buildData.Status -eq 'notStarted')
            {
                Write-Verbose ("[{0}] Current status is: [$($buildData.Status)]. Sleeping for [$($PollingInterval)] seconds" -f (Get-Date -Format G))
                Start-Sleep -Seconds $PollingInterval
            }
            Else
            {
                Return $buildData
            }
        }
        Until ((Get-Date) -ge $_timeout)

        Write-Error "[$($MyInvocation.MyCommand.Name)]: Timed out after [$TimeOut] seconds. [$($buildData._links.web.href)]"
    }
    
    end
    {
    }
}
# Wait-APRelease.ps1
function Wait-APRelease
{
    <#
    .SYNOPSIS
 
    Waits for an Azure Pipelines release to exit 'inProgress' status.
 
    .DESCRIPTION
 
    Waits for a Azure Pipelines release to exit 'inProgress' status based on the release id.
    The id can be retrieved by using Get-APReleaseList.
 
    .PARAMETER Instance
     
    The Team Services account or TFS server.
     
    .PARAMETER Collection
     
    For Azure DevOps the value for collection should be the name of your orginization.
    For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
 
    .PARAMETER Project
     
    Project ID or project name.
 
    .PARAMETER ApiVersion
     
    Version of the api to use.
 
    .PARAMETER PersonalAccessToken
     
    Personal access token used to authenticate that has been converted to a secure string.
    It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
    https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
     
    .PARAMETER Credential
 
    Specifies a user account that has permission to send the request.
 
    .PARAMETER Proxy
     
    Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
 
    .PARAMETER ProxyCredential
     
    Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
 
    .PARAMETER Session
 
    Azure DevOps PS session, created by New-APSession.
 
    .PARAMETER ReleaseId
 
    The ID of the release
 
    .PARAMETER Environment
 
    The name of the environment to check the status for.
 
    .PARAMETER Timeout
     
    Timeout threshold in seconds.
 
    .PARAMETER PollingInterval
     
    The number of seconds to wait before checking the status of the release, defaults to 1.
 
    .INPUTS
     
    None, does not support pipeline.
 
    .OUTPUTS
 
    PSObject, Azure Pipelines release(s)
 
    .EXAMPLE
 
    Waits for the release with the id of '7' for the 'myFirstProject.
 
    Wait-APRelease -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -ReleaseId 7
 
    .EXAMPLE
 
    Waits for only 30 seconds for the release with the id of '9'.
 
    Wait-APRelease -Session 'mySession' -ReleaseId 7 -Timeout 30
 
    .LINK
 
    https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases?view=azure-devops-rest-5.0
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
    Param
    (
        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [uri]
        $Instance,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Collection,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $Project,

        [Parameter(Mandatory,
            ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(Mandatory,
            ParameterSetName = 'ByCredential')]
        [string]
        $ApiVersion,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Security.SecureString]
        $PersonalAccessToken,

        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $Credential,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [string]
        $Proxy,

        [Parameter(ParameterSetName = 'ByPersonalAccessToken')]
        [Parameter(ParameterSetName = 'ByCredential')]
        [pscredential]
        $ProxyCredential,

        [Parameter(Mandatory,
            ParameterSetName = 'BySession')]
        [object]
        $Session,

        [Parameter(Mandatory)]
        [int]
        $ReleaseId,

        [Parameter(Mandatory)]
        [string]
        $Environment,

        [Parameter()]
        [int]
        $Timeout = 300,

        [Parameter()]
        [int]
        $PollingInterval = 1
    )

    begin
    {
        If ($PSCmdlet.ParameterSetName -eq 'BySession')
        {
            $currentSession = $Session | Get-APSession
            If ($currentSession)
            {
                $Instance = $currentSession.Instance
                $Collection = $currentSession.Collection
                $Project = $currentSession.Project
                $PersonalAccessToken = $currentSession.PersonalAccessToken
                $Credential = $currentSession.Credential
                $Proxy = $currentSession.Proxy
                $ProxyCredential = $currentSession.ProxyCredential
                If ($currentSession.Version)
                {
                    $ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
                }
                else
                {
                    $ApiVersion = $currentSession.ApiVersion
                }
            }
        }
    }
    
    process
    {
        $_timeout = (Get-Date).AddSeconds($TimeOut)
        $getAPReleaseSplat = @{
            Collection = $Collection
            Instance   = $Instance
            ReleaseId  = $ReleaseId
            Project    = $Project
            ApiVersion = $ApiVersion
        }
        If ($PersonalAccessToken)
        {
            $getAPReleaseSplat.PersonalAccessToken = $PersonalAccessToken
        }
        If ($Credential)
        {
            $getAPReleaseSplat.Credential = $Credential
        }
        If ($Proxy)
        {
            $getAPReleaseSplat.Proxy = $Proxy
        }
        If ($ProxyCredential)
        {
            $getAPReleaseSplat.ProxyCredential = $ProxyCredential
        }
        Do
        {
            $releaseData = Get-APRelease @getAPReleaseSplat -ErrorAction 'Stop'
            $_environmentStatus = $releaseData.environments | Where-Object { $PSItem.name -eq $Environment } | Select-Object -ExpandProperty 'Status'
            If ($_environmentStatus -eq 'inProgress' -or $_environmentStatus -eq 'queued')
            {
                Write-Verbose ("[{0}] Current status is: [$($_environmentStatus)]. Sleeping for [$($PollingInterval)] seconds" -f (Get-Date -Format G))
                Start-Sleep -Seconds $PollingInterval
            }
            Else
            {
                Return $releaseData
            }
        }
        Until ((Get-Date) -ge $_timeout)
        
        Write-Error "[$($MyInvocation.MyCommand.Name)]: Timed out after [$TimeOut] seconds. [$($releaseData._links.web.href)]"
    }
    
    end
    {
    }
}
# Write-APLogMessage.ps1
function Write-APLogMessage
{
    <#
    .SYNOPSIS
 
    Pipeline invocation command that writes a log message to a powershell channel or an Azure DevOps pipeline timeline record log.
 
    .DESCRIPTION
 
    Writes a log message to a powershell channel or an Azure DevOps pipeline timeline record log.
    Pipeline invocation commands make changes during pipeline execution. If the command is excuted in a console window the command will output logging messages.
 
 
    .PARAMETER Message
 
    The log message.
 
    .PARAMETER Error
 
    Switch, the log should be an error.
 
    .PARAMETER Warning
 
    Switch, the log should be a warning.
 
    .INPUTS
 
    None, does not support the pipline
 
    .OUTPUTS
 
    Log, error or warning.
 
    .EXAMPLE
 
    Write-APLogMessage -Message 'This is an error message!' -Error
 
    .EXAMPLE
 
    Write-APLogMessage -Message 'This is an warning message!' -Warning
 
    #>

    [CmdletBinding(DefaultParameterSetName = 'ByError')]
    param
    (
        [Parameter(Mandatory)]
        [string]
        $Message,

        [Parameter(Mandatory,
            ParameterSetName = 'ByError')]
        [switch]
        $Error,

        [Parameter(Mandatory,
            ParameterSetName = 'ByWarning')]
        [switch]
        $Warning
    )
    begin
    {
        If ($env:Build_BuildId -or $env:Release_DefinitionId)
        {
            $pipelineInvocation = $true
        }
    }
    process
    {
        Switch ($PSCmdlet.ParameterSetName)
        {
            'ByError'
            {
                If ($pipelineInvocation)
                {
                    Write-Host "##vso[task.logissue type=error;]$Message"
                }
                else
                {
                    Write-Error -Message $Message
                }
            }
            'ByWarning'
            {
                If ($pipelineInvocation)
                {
                    Write-Host "##vso[task.logissue type=warning;]$Message"
                }
                else
                {
                    Write-Warning -Message $Message
                }
            }
        }
    }
    end
    {

    }
}
# Imported from [D:\_work\1\s\AzurePipelinesPS\Tests]