The following forum(s) have migrated to Microsoft Q&A (Preview): Azure Active Directory!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Azure b2c using powershell RRS feed

Answers

  • When using New-AzureADUser you set the -CreationType to LocalAccount to create a local account for a B2C tenant. https://docs.microsoft.com/en-us/powershell/module/azuread/new-azureaduser?view=azureadps-2.0

    See similar thread

    For custom attributes, the correct way to add them is through the Azure portal.

    You can, however, update existing users' custom attributes after they are created by using Powershell. 

    Connect-AzureAD  //connect to your b2c tenant
    
    $userNameList = <string array list of signin name of users in your CSV>
    $ExtensionName = <extension name of your company id attribute>
    $ExtensionValue = <value of your companyID>
    
    
    $userlist = Get-AzureADUser | Where-Object {$userNameList.Contains($_.SignInNames[0].Value) }
    
    foreach( $user in $userlist){
       Set-AzureADUserExtension -ExtensionName $ExtensionName -ExtensionValue $ExtensionValue -ObjectId $user.ObjectId
    } 

    More in-depth explanation here.


    Please take a moment to "Mark as Answer" and/or "Vote as Helpful" wherever applicable. Thanks!

    Monday, December 2, 2019 8:02 PM

All replies

  • When using New-AzureADUser you set the -CreationType to LocalAccount to create a local account for a B2C tenant. https://docs.microsoft.com/en-us/powershell/module/azuread/new-azureaduser?view=azureadps-2.0

    See similar thread

    For custom attributes, the correct way to add them is through the Azure portal.

    You can, however, update existing users' custom attributes after they are created by using Powershell. 

    Connect-AzureAD  //connect to your b2c tenant
    
    $userNameList = <string array list of signin name of users in your CSV>
    $ExtensionName = <extension name of your company id attribute>
    $ExtensionValue = <value of your companyID>
    
    
    $userlist = Get-AzureADUser | Where-Object {$userNameList.Contains($_.SignInNames[0].Value) }
    
    foreach( $user in $userlist){
       Set-AzureADUserExtension -ExtensionName $ExtensionName -ExtensionValue $ExtensionValue -ObjectId $user.ObjectId
    } 

    More in-depth explanation here.


    Please take a moment to "Mark as Answer" and/or "Vote as Helpful" wherever applicable. Thanks!

    Monday, December 2, 2019 8:02 PM
  • Thankyou very much for the reply,

    The code above runs fine, but due to lack of knowledge in B2C, I don't know how to see the attribute that I set.

    Can you help me with that ? I don't know from where to begin with.

    Tuesday, December 3, 2019 5:26 AM
  • Once we create a custom attribute in B2C, the backend will create an key for it. They key is the value of the ExtensionName. To find the key you can run Get-AzureADExtensionProperty. There you will see the key for the custom attribute (in the example below, you can see the name of the CompanyId custom attribute in the key)

    enter image description hereThis blog also gives a good example for this. https://www.techmikael.com/2017/11/fetching-custom-attributes-from-azure.html


    Please take a moment to "Mark as Answer" and/or "Vote as Helpful" wherever applicable. Thanks!

    Thursday, December 5, 2019 1:27 AM