src/Get-cciAzDevOpsCredential.ps1

function Get-cciAzDevOpsCredential {
    [CmdletBinding()]
    param (
        $keyvaultName,
        $secretName,
        $patusername
    )
    begin {
        Write-Verbose "Started running $($MyInvocation.MyCommand)"
    }
    process {
        if ($null -eq (Get-AzContext)) {
            Connect-cciAzAccount
        }
        $secretValue = (Get-AzKeyVaultSecret -VaultName $keyvaultName -Name $secretName).SecretValueText
        $pat = ConvertTo-SecureString $secretValue -AsPlainText -Force
        New-Object PSCredential -ArgumentList $patusername, $pat
    }
    end {
        Write-Verbose "Finished running $($MyInvocation.MyCommand)"
    }
}