8

Is it possible to create Azure AD B2C tenants programmatically (e.g. with Powershell, REST API)?

We are developing a multi-tenant SaaS solution for which we would like to create an Azure B2C tenant automatically whenever a new tenant registers.

Vic
  • 442
  • 2
  • 12
Rainer
  • 676
  • 7
  • 15

2 Answers2

2

I'm afraid currently you cannot create Azure AD using either the APIs or using PowerShell. Although you can create additional directories in a subscription you cannot create one using any automation.

Martyn C
  • 1,109
  • 9
  • 18
0

You can use PowerShell AzureADPreview 2.0 module to manage custom policies, applications, etc. Although not such a complete thing like ARM Templates, but you can automate many things for now.

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 custom policies:
Get-AzureADMSTrustFrameworkPolicy

# upload a policy:
$policyId = "B2C_1A_TrustFrameworkBase"
$policyFileName "YourTrustFrameworkBase.xml"
Set-AzureADMSTrustFrameworkPolicy -Id $policyId -InputFilePath $policyFileName

#list your all apps    
Get-AzureADApplication 

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

# create an application
$applicationName = "yourappname"
$application = New-AzureADApplication -DisplayName $applicationName -PublicClient $true etc
g.pickardou
  • 32,346
  • 36
  • 123
  • 268