I’m trying to create new Azure Active Directory application, using this PowerShell command:
$SecurePassword=ConvertTo-SecureString {password} -asplaintext -force
New-AzADApplication -DisplayName {Display name} -HomePage {Home page URL} -IdentifierUris {Application identifier} -Password $SecurePassword
But I get an error that says Cannot convert value "System.Security.SecureString" to type "Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.IMicrosoftGraphPasswordCredential[]".
Here’s the full error:
New-AzADApplication: Cannot process argument transformation on parameter 'PasswordCredentials'. Cannot convert value "System.Security.SecureString" to type "Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.IMicrosoftGraphPasswordCredential[]". Error: "Cannot convert the "System.Security.SecureString" value of type "System.Security.SecureString" to type "Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.IMicrosoftGraphPasswordCredential"."
Yet, I can’t find any information about how to convert another way. I’m relatively new to PowerShell though. Anyone know how to resolve this error? Thank you.
The command came from here:
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-rm-rest
2
Answers
The latest New-AzADApplication cmdlet has not contain the Password parameter. Thats why it is throwing the below error.
Workaround to avoid the issue:
New-AzADApplication
as a Service principalNew-AzADServicePrincipal
.I don’t know how Delliganesh got this to work with a -Password property, as that isn’t a member of New-AzADAppCredential. When you do this you are asking the application to create a new key and secret for you, that you must record in order to work with it. If you pipe New-AzADAppCredential -ObjectId "xxx…." to Get-Member, you will see that there isn’t a -Password property for it. So, in order to get this to work, do the following:
$myApp = New-AzADApplication -DisplayName "Application Display Name"
-IdentifierUris "Application Identifier Url"
New-AzADServicePrincipal -ApplicationId $myApp.AppId
Then, in the Azure Portal, go to App Registrations and locate your new App. In the Overview for it, you will see the Object ID. Copy that to the clipboard, and then:
New-AzADAppCredential -ObjectId "xxx….."
This will generate the key and secret that I mentioned earlier, which you should make a note of. Also note the expiry date and time if you plan to use them long-term.