Skip to content

Instantly share code, notes, and snippets.

@bachoang
Created January 3, 2019 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bachoang/c5a8c49ed9e831e98925e25cf3b2ffd7 to your computer and use it in GitHub Desktop.
Save bachoang/c5a8c49ed9e831e98925e25cf3b2ffd7 to your computer and use it in GitHub Desktop.
PS script to create an AAD App and set the permission of the app to accesss azure key vault secret
$x509 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$x509.Import("C:\Users\<name>\Documents\learn\key vault\blog\KVWebApp.cer")
$credValue = [System.Convert]::ToBase64String($x509.GetRawCertData())
Connect-AzureAD
$adapp = New-AzureRmADApplication -DisplayName "KVWebApp" -HomePage "http://kvwebapp" -IdentifierUris "http://kvwebapp" -CertValue $credValue -StartDate $x509.NotBefore -EndDate $x509.NotAfter
$sp = New-AzureRmADServicePrincipal -ApplicationId $adapp.ApplicationId
Set-AzureRmKeyVaultAccessPolicy -VaultName 'BlogKV123' -ServicePrincipalName "http://kvwebapp" -PermissionsToSecrets get,list,set,delete,backup,restore,recover,purge -ResourceGroupName 'BlogKVRG'
# get the thumbprint to use in your app settings
$x509.Thumbprint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment