将证书上传到AAD应用程序的powershell命令是什么?

时间:2017-11-30 06:40:36

标签: powershell azure azure-active-directory

在Azure门户中,我可以在AAD下创建一个应用程序,导航到“主页” (myTenant) - >应用注册 - > (myApp) - >设置 - >密钥“,将作为证书的公钥上传到应用程序密钥。使用门户网站UI很容易。但是如何使用Powershell命令上传证书?

谢谢,

2 个答案:

答案 0 :(得分:2)

您正在寻找New-AzureRmADAppCredential命令 https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/new-azurermadappcredential?view=azurermps-5.0.0

文章中的示例2应该适合您

---------------- 8< --------------------

$cer = New-Object System.Security.Cryptography.X509Certificates.X509Certificate 
$cer.Import("C:\myapp.cer") 
$binCert = $cer.GetRawCertData() 
$credValue = [System.Convert]::ToBase64String($binCert)

New-AzureRmADAppCredential -ApplicationId 4589cd6b-3d79-4bb4-93b8-a0b99f3bfc58 -CertValue $credValue -StartDate $cer.GetEffectiveDateString() -EndDate $cer.GetExpirationDateString()

答案 1 :(得分:0)

您可以将New-AzureRmADAppCredential用于Adds a credential to an existing Azure AD application

Login-AzureRmAccount
$cert = New-Object    System.Security.Cryptography.X509Certificates.X509Certificate("PATH_TO_CER_FILE")
$key = [System.Convert]::ToBase64String($cert.GetRawCertData())
New-AzureRmADAppCredential -ApplicationId d3fdf244-xxxx-xxxx-8faa-4a22b9739374  -CertValue $key

enter image description here