Hi @Selvin Pudusserry , thanks for the follow-up. You will indeed need to use a different approach. You can use the Graph API or PowerShell to achieve this.
Graph API
- Register an Application in Azure AD B2C:
- Go to the Azure portal and navigate to Azure AD B2C.
- Select "App registrations" and then "New registration".
- Provide a name for the app and set the supported account types to "Accounts in this organizational directory only".
- Once the app is registered, note down the Application (client) ID and Directory (tenant) ID.
- Under "Certificates & secrets", create a new client secret and note it down.
- Grant API Permissions:
- In the app registration, go to "API permissions".
- Add permissions for
User.ReadWrite.All
andDirectory.ReadWrite.All
under Microsoft Graph. - Grant admin consent for the permissions.
- Prepare Your CSV Data:
- Ensure your CSV contains the necessary fields. For example:
userPrincipalName,displayName,password,signInNames ******@gmail.com,User One,Password123,{"type":"emailAddress","value":"******@gmail.com"} ******@yahoo.com,User Two,Password123,{"type":"emailAddress","value":"******@yahoo.com"}
- Ensure your CSV contains the necessary fields. For example:
- Write a Script to Import Users: Here's an example PowerShell script using the Microsoft Graph API to import users:
# Install the Microsoft.Graph module if not already installed Install-Module -Name Microsoft.Graph -Force -AllowClobber # Import the module Import-Module Microsoft.Graph # Connect to Microsoft Graph $tenantId = "your-tenant-id" $clientId = "your-client-id" $clientSecret = "your-client-secret" $token = (Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method Post -Body @{ client_id = $clientId scope = "https://graph.microsoft.com/.default" client_secret = $clientSecret grant_type = "client_credentials" }).access_token # Read CSV file $users = Import-Csv -Path "path-to-your-csv-file.csv" # Define API endpoint $graphApiUrl = "https://graph.microsoft.com/v1.0/users" foreach ($user in $users) { $userPayload = @{ accountEnabled = $true displayName = $user.displayName mailNickname = $user.displayName userPrincipalName = $user.userPrincipalName passwordProfile = @{ forceChangePasswordNextSignIn = $true password = $user.password } signInNames = @($user.signInNames | ConvertFrom-Json) } $userJson = $userPayload | ConvertTo-Json -Depth 10 $response = Invoke-RestMethod -Uri $graphApiUrl -Method Post -Headers @{Authorization = "Bearer $token"} -Body $userJson -ContentType "application/json" Write-Output $response }
Azure AD PowerShell
Alternatively, you can use Azure AD PowerShell to achieve the same goal. Here’s a brief example:
- Install AzureAD Module:
Install-Module -Name AzureAD
- Connect to Azure AD:
Connect-AzureAD -TenantId "your-tenant-id"
- Script to Create Users:
# Read CSV file $users = Import-Csv -Path "path-to-your-csv-file.csv" foreach ($user in $users) { $passwordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile $passwordProfile.Password = $user.password $passwordProfile.ForceChangePasswordNextLogin = $true New-AzureADUser -DisplayName $user.displayName ` -PasswordProfile $passwordProfile ` -UserPrincipalName $user.userPrincipalName ` -MailNickName $user.displayName ` -AccountEnabled $true ` -SignInNames @(@{Type="emailAddress"; Value=$user.userPrincipalName}) }
Notes:
- Sign-in Names:
signInNames
is crucial in Azure AD B2C as it allows users to sign in with their email addresses, even if the UPN is different. - Password Handling: Ensure you handle passwords securely and comply with your organization's password policies.
- Testing: Always test the script with a few users before running it for the entire dataset.
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James