2016-04-25 69 views
2

我试图在使用PowerShell的Azure AD应用程序中添加密钥。不幸的是,我首先尝试使用Azure CLI,但经过一些研究和一些计算器的回答后,我发现,这是无法完成的。通过Powershell添加密钥的Azure AD应用程序

我试图通过自动化PowerShell与下面的链接任务:http://blog.davidebbo.com/2014/12/azure-service-principal.html

我还执行以下步骤: https://blogs.technet.microsoft.com/kv/2015/06/02/azure-key-vault-step-by-step/

有什么方法来创建/检索下面的东西Powershell:

VaultUrl, AuthClientId, AuthClientSecret。

回答

0

下面将从现有的AD应用程序检索客户端ID:

$ADApp = Get-AzureRmADApplication -DisplayName "AzureADApplicationName" 
write-host $ADApp.ApplicationId 

下面将检索库的URI:

$KeyVault= Get-AzureRmKeyVault -VaultName "VaultName" 
write-host $KeyVault.VaultUri 

我也在寻找选项,从PowerShell中添加关键。当我手动添加密钥时,显示消息显示“复制并存储密钥值,离开此页面后将无法恢复密钥值”。但仍试图找出使用PowerShell检索密钥(ClientSecret)的选项。

+0

我有同样的问题,你有没有想过这个呢? –

+0

没有。还没有找到一种方法来从脚本中检索它。现在我正在手动做。 – Magg

1

这是可以做到用两种方法新AzureRmADApplication(包括它,当你创建应用程序),但显然不能与集-AzureRmADApplication(即创建应用程序后设置;我不确定是否有通过PowerShell的方法)。但是,仅仅从了解方法来确定这一点并不清楚。这个网站让我回答:https://sabin.io/blog/adding-an-azure-active-directory-application-and-key-using-powershell/

要点是您必须提供这些方法引用的PasswordCredentials,尽管Azure门户似乎将其称为密钥,而某些PowerShell命令(如SqlAzureAuthenticationContext)将您设置为Secret的值(所有这些都是令人困惑的词汇)。以下是我如何使用凭证创建的:

# Be sure to note $KeyValue! It can't be retrieved. 
# It's the "Secret" you can pass to methods like Add-SqlAzureAuthenticationContext in order to authenticate. 
$KeyValue = [guid]::NewGuid() 
Write-Output "The password you've set is $KeyValue" 

$psadCredential = New-Object Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADPasswordCredential 
$startDate = Get-Date 
$psadCredential.StartDate = $startDate 
$psadCredential.EndDate = $startDate.AddYears(1) 
$psadCredential.KeyId = [guid]::NewGuid() 
$psadCredential.Password = $KeyValue 

$adApplication = New-AzureRmADApplication –DisplayName “MyNewApp”` 
-HomePage "http://MyNewApp"` 
-IdentifierUris "http://MyNewApp"` 
-PasswordCredentials $psadCredential 
+0

使用最新版本的AzureRM,** PSADPasswordCredentials **对象已移至** Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory.PSADPasswordCredential ** – codeConcussion

相关问题