functions/New-AadApplicationCertificate.ps1

New-AadApplicationCertificate
{
    Param(
        $ClientId
    )

    # Create Self-Signed Certificate
    $cert=New-SelfSignedCertificate -Subject "CN=Aad-$ClientId" -CertStoreLocation "Cert:\CurrentUser\My"  -KeyExportPolicy Exportable -KeySpec Signature
    
    # Get Application object from Azure AD
    $app = Get-AadApplication

    # Export Certificate
    $Path = "aad-$ClientId.cer"
    Export-Certificate -Cert $cert -FilePath $Path

    Write-Host "Exported Public Key of created Self-Signed Certificate to..."
    Wite-Host "$PSScriptRoot\$Path"
}