Home > Enterprise >  how do I retrieve the password from the MicrosoftGraphPasswordCredential object
how do I retrieve the password from the MicrosoftGraphPasswordCredential object

Time:04-21

I have to update a Script which should create an application in Azure and subsequently use it to traverse resources. Among the commands to update is to create a credential for the application created.

$AppSPN = New-AzADServicePrincipal -DisplayName "Move_Validation_SPN"

subsequently I need to use a credential to traverse the resources, according to the same Microsoft documentation, it can be created like this:

$creds = New-Object `
             -TypeName "Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.MicrosoftGraphPasswordCredential" `
             -Property @{ 'DisplayName' = $name; 'StartDateTime' = $startDate; 'EndDateTime' = $endDate }
    
    New-AzADAppCredential -ApplicationId $AppSPN.appId -PasswordCredentials @creds

Here comes the question, when I create a Token, how do I retrieve the password from the MicrosoftGraphPasswordCredential object? which is: $creds

$Token = Get-Token -TenantId $TenantId  -SubscriptionID $SourceSub.Id -ApplicationID $AppSPN.appID -ApplicationKey $creds

CodePudding user response:

From version 6.6.0, there are breaking changes in this cmdlet New-AzADAppCredential.

As mentioned in this MS Doc, Az PowerShell cmdlets module moved from Azure AD Graph to Microsoft Graph. So, it is better to use the cmdlet of New-AzureADApplicationPasswordCredential.

enter image description here

Workaround: enter image description here

As mentioned here, there should be a mistake in the official doc, in the example, it uses the New, not Get.If you try New, it appears like the doc.

Source: New-AzureADApplicationPasswordCredential

  • Related