How to script azure b2c applications creation

Viewed 546
2 Answers

Currently, it is only possible to manage B2C policies programmatically. Since B2C Custom Policies went GA, it is now possible to create custom policies using PowerShell.

Refer this: https://stackoverflow.com/a/56252795/10571855

However, the feature request for programmatic app mgmt is here. Please vote for it so that we can let you know when it is available for preview.

You can use PowerShell AzureADPreview 2.0 module to create applications.

Full doc is here: AzureADPreview 2 docs

I had no success to install this module to "old" PowerShell (5.x) so I gave a shot to the 'new' PowerShell 7 (Core). The only issue with PowerShell 7 and AzureAD module is that Connect-AzureAD uses a cryptographic function which is not in .NET Core, so you must import the AzureADPreview module using the -UseWindowsPowerShell option.

Here is a sample, works with PowerShell 7:

Install-Module AzureADPreview
Import-Module AzureADPreview -UseWindowsPowerShell
$tenantId = "yourb2ctenant.onmicrosoft.com"

# Note: this will interactively ask your credentials. 
#       If you want to run this unattended, use the -Credential parameter with a PSCredential object with a SecureString
Connect-AzureAD -TenantId $tenantId

# ready to go 

#list your all apps    
Get-AzureADApplication 

# examine one of you app and get ideas 
$application = Get-AzureADApplication -ObjectId af46a788-8e55-4301-b2df-xxxxxxxxx 

# create and application
$applicationName = "yourappname"
$application = New-AzureADApplication -DisplayName $applicationName -PublicClient $true etc
Related