Azure AD 应用程序通过 Powershell 添加密钥 [英] Azure AD application adding a key via Powershell

查看:9
本文介绍了Azure AD 应用程序通过 Powershell 添加密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PowerShell 在我的 Azure AD 应用程序中添加一个密钥.不幸的是,我首先尝试使用 Azure CLI,但经过一些研究和一些 stackoverflow 答案后,我发现这无法完成.

I'm trying to add a key in my Azure AD application using PowerShell. Unfortunately i was try first with Azure CLI, but after some research and some stackoverflow answers I figure out, that this cannot be done.

我正在尝试通过 Powershell 自动执行以下链接中的任务:http://blog.davidebbo.com/2014/12/azure-service-principal.html

I'm trying to automate the task from the link below via 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 中创建/检索以下内容:

Is there any way to create/retrieve the following things in Powershell:

VaultUrl,AuthClientId,AuthClientSecret.

VaultUrl, AuthClientId, AuthClientSecret.

推荐答案

这可以使用 New-AzureRmADApplication 方法(在创建应用程序时包含它)来完成,但显然不能使用 Set-AzureRmADApplication(即设置创建应用程序后它;我不确定有没有办法通过powershell做到这一点).但是仅从知道方法就不清楚如何设置它.这个网站让我得到了答案:https://sabin.io/blog/adding-an-azure-active-directory-application-and-key-using-powershell/.

This can be done using either the method New-AzureRmADApplication (to include it when you create the application), but apparently not with Set-AzureRmADApplication (i.e. to set it after creating the app; I'm not sure there is a way to do that via powershell). But it's not clear how to set this just from knowing the methods. This site led me to the answer: https://sabin.io/blog/adding-an-azure-active-directory-application-and-key-using-powershell/.

要点是您必须提供这些方法称为 PasswordCredentials 的内容,尽管 Azure 门户似乎将它们称为密钥,并且一些 powershell 命令,如 SqlAzureAuthenticationContext 调用您设置 Secret 的值(所有这些都令人困惑条款).以下是我使用凭据创建的方法:

The gist is that you have to provide what those methods refer to as PasswordCredentials, though the Azure portal seems to call them keys, and some powershell commands, like SqlAzureAuthenticationContext call the value you are setting the Secret (all of which are confusing terms). Here's how I did it to create with the credential:

# 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

这篇关于Azure AD 应用程序通过 Powershell 添加密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆