Get-AzCertificateThumbprint.psm1
function Get-CertThumbprint { <# .SYNOPSIS Gets a azure keyvault certificate thumbprint with interactive connecting to azure account. .DESCRIPTION returns a az certificate thumbprint from a key vault. .PARAMETER KeyVault Azure keyvault that contains a certificate to fetch a thumbprint. .PARAMETER CertificateName Name of a certificate to fetch a thumbprint. .EXAMPLE PS C:\> Get-AzCertificateThum This example will prompt for the Account SID and Auth Token to configure the API connection. .EXAMPLE PS C:\> Get-CertThumbprint -KeyValut "MyAzKeyVault" -CertificateName "MyAzKeyVaultCertificateName" #> param( [Parameter(Mandatory = $true)] [string] $KeyVault, [Parameter(Mandatory = $true)] [string] $CertificateName ) $t = Get-AzAccessToken -ResourceUrl "https://vault.azure.net" $kvToken = $t.Token $certificateUri = "https://$KeyVault.vault.azure.net/secrets/$CertificateName/?api-version=7.1" $certificateResponse = Invoke-WebRequest $certificateUri -Method GET -Headers @{"Authorization" = "Bearer $kvToken" } -UseBasicParsing | ConvertFrom-Json $certPath = ([System.IO.Path]::Combine($PSScriptRoot, "TempCertificate")) $base64certificate = $certificateResponse.value $base64Certificate | Out-File $certPath $certificate = Import-PfxCertificate -FilePath $certPath -CertStoreLocation "Cert:\LocalMachine\My" $thumbprint = $certificate.Thumbprint return $thumbprint } |