Upload Azure AAD B2C Premium Policy with Powershell

If you like all of your interactions with Azure to be through Powershell (who doesn’t like to automate), then you’ll want to do the same thing for B2C Policies.

Don’t try this before you have your b2c directory whitelisted to work with the B2C Policy Upload feature. You’ll know if this is possible, if in the Azure Portal you’re able to upload a policy.

#Impo the b2c module
#ExploreAdmin cmdlets will get rolled into the standard Azure Powershell module at some point.  Cmdlets will undoubtably be renamed.
#Until there is a better source, grab the dll from here; https://github.com/beejones/B2CDemoTools/blob/master/ExploreAdmin/ExploreAdmin.dll
cd C:tempExploreAdmin
import-module .ExploreAdmin.dll

#Define user vars
$tenantId = "mytenant.onmicrosoft.com"
$policyFileLocation = "C:MyPoliciesPolicy1.xml"

#Upload the policy, you'll be propmpted to login
New-TrustFramework -TenantId $tenantId -ContentFilename $policyFileLocation -OverwriteIfExists -ShowRemoteError


One Reply to “Upload Azure AAD B2C Premium Policy with Powershell”

  1. Hey Gordon, thanks for this. I was attempting to import the ExploreAdmin.dll and it’s throwing an error.

    PackageManagement\Install-Package : No match was found for the specified search criteria and module name ‘.ExploreAdmin.dll’.

    I’ve searched around, but have not found what I need to install to import a .dll. Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *