简体   繁体   English

使用 powershell 重置 Azure 服务主体的客户端密码

[英]Reset the client secret of Azure Service Principal using powershell

Using powershell commands i want to reset the Service Principal client secret.使用 powershell 命令我想重置服务主体客户端密码。

I followed the below steps from the article https://docs.microsoft.com/en-us/powershell/azure/create-azure-service-principal-azureps?view=azps-5.8.0 but it didnot reset the password我按照文章https://docs.microsoft.com/en-us/powershell/azure/create-azure-service-principal-azureps?view=azps-5.8.0中的以下步骤操作,但它没有重置密码

Remove-AzADSpCredential -DisplayName ServicePrincipalName
$newCredential = New-AzADSpCredential -ServicePrincipalName ServicePrincipalName

can you tell what i am doing wrong.你能告诉我我做错了什么吗? I just want to reset the secret and have new one我只想重置秘密并拥有一个新的

I executed the above command and then i went to the app registration of that service principal and there i went to certificates & secrets i see it has not createed new secret.我执行了上述命令,然后我去了该服务主体的应用程序注册,在那里我去了证书和秘密,我看到它没有创建新的秘密。

Using bash i am able to reset the password by executing the below command but i want it to be done using powershell command使用 bash 我可以通过执行以下命令来重置密码,但我希望使用 powershell 命令来完成

az ad sp credential reset --name

I went to the app registration of that service principal and there I went to certificates & secrets I see it has not created new secret.我去了那个服务主体的应用程序注册,在那里我去了证书和秘密,我看到它没有创建新的秘密。

Well, actually the command New-AzADSpCredential did create a new secret for you.好吧,实际上New-AzADSpCredential命令确实为您创建了一个新秘密。 Firstly, you need to know the relationship between App Registration(AD App) and Service principal, see Application and service principal objects in Azure Active Directory .首先,您需要了解应用注册(AD App)和服务主体之间的关系,请参阅Azure Active Directory 中的应用程序和服务主体对象

In short, the service principal is the local representation for the AD App in a specific tenant.简而言之,服务主体是特定租户中 AD 应用程序的本地表示。 When you create the secret for the service principal, it will not appear in the Certificates & secrets blade, you can just get it with Get-AzADSpCredential .当您为服务主体创建密钥时,它不会出现在Certificates & secrets刀片中,您可以使用Get-AzADSpCredential获取它。

If you want to reset the secret that you can find in the portal, you need to reset the sceret for the AD App(ie App Registration) via Remove-AzADAppCredential and New-AzADAppCredential .如果要重置可在门户中找到的密码,则需要通过Remove-AzADAppCredentialNew-AzADAppCredential重置 AD 应用程序的密码(即应用注册)。

You could refer to the sample below, it resets a secret with value ce96a0ed-5ae8-4a5a-9b3c-630da9ea3023 , it is valid for one year, you can find it in the portal.您可以参考下面的示例,它重置了一个值为ce96a0ed-5ae8-4a5a-9b3c-630da9ea3023 ,有效期为一年,您可以在门户中找到它。

$obj = (Get-AzADApplication -DisplayName joyappv2).ObjectId
Remove-AzADAppCredential -ObjectId $obj -Force
$azurePassword = ConvertTo-SecureString "ce96a0ed-5ae8-4a5a-9b3c-630da9ea3023" -AsPlainText -Force
$date = Get-Date
$newCredential = New-AzADAppCredential -ObjectId $obj -Password $azurePassword -StartDate $date -EndDate $date.AddYears(1)

Note: You could not get the secret value again after creating it, so please store it when creating.注意:创建后无法再次获取密值,请在创建时保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Terraform 为 Azure 服务主体创建客户端密码 - How to create client secret for Azure Service Principal using Terraform Terraform Azure 服务主体客户端机密过期 - Terraform Azure Service Principal Client Secret expiration Terraform 通过服务主体和客户机密对 Azure 进行身份验证 - Terraform authenticating to azure by service principal and client secret 如何在 Powershell 中检索 Azure 服务主体的秘密 7 - How to retrieve Azure Service Principal's secret in Powershell 7 Azure 使用服务主体登录失败并出现 401 - 提供的客户端密码无效 - Azure Login Using Service Principal is failing with 401 - Invalid client secret provided Azure Active Directory 应用服务主体更新客户端机密 - Azure Active Directory App service Principal update client secret 如何从现有的 Azure 服务主体获取客户端密码 - How to get client secret from existing Azure service principal 如何使用自动化帐户 PowerShell Runbook 重置 Azure 服务主体的凭据? - How to reset credentials of an Azure service principal using an automation account PowerShell runbook? 使用Windows Azure服务获取客户端机密 - Get Client Secret using Windows Azure Service 到期时自动更新服务主体客户端密码? - Automatically update Service Principal client secret on expiry?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM