Share via

How to Bulk upload using Graph SDK powershell

Anonymous
2023-08-02T12:24:57+00:00

Hi, I'm trying to bulk upload a user from csv using powershell but I can't upload more than 10 user per run. I found a solution using a graph sdk powershell script but unfortunately I cant convert the script to the new one. Can someone help me to convert my script. I really appreciate if someone will help me with my problem. $userName = "Admin" $password = "Password" $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $securePassword Connect-MsolService -Credential $credential $users = Import-Csv D:\O365\bulk2.csv Import-Csv -Path D:\O365\bulk2.csv | ForEach-Object {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -LicenseAssignment $_.AccountSkuId -Password $_.Password -UsageLocation $_.UsageLocation }

Microsoft 365 and Office | Install, redeem, activate | Other | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2023-08-29T03:21:29+00:00

    Excuse me, did your import succeed later?

    May I ask what values ​​are filled in the first column of your csv file? Because I tried for a long time, but I made mistakes, can you teach me, please?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-08-28T11:42:22+00:00

    What is the field format of the csv file? I can't make it, thanks

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-08-04T14:00:48+00:00

    It looks like you’re encountering an “Insufficient privileges to complete the operation” error when trying to create a new user using the New-MgUser cmdlet.

    This error typically occurs when the account you’re using to run the script doesn’t have the necessary permissions to create new users in your organization. To fix this issue, you can try the following steps:

    Make sure that you’re signed in to the Microsoft Graph API with an account that has the necessary permissions to create new users. You can do this by running the Connect-MgGraph cmdlet and signing in with an account that has the Global Administrator or User Administrator role.

    If you’re already signed in with an account that has the necessary permissions, try signing out and then signing back in again by running the Disconnect-MgGraph and Connect-MgGraph cmdlets.

    If you’re still encountering the error after trying these steps, you may need to contact your organization’s IT administrator for assistance.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-08-03T01:32:13+00:00

    Hi, @AnnaThomasH,

    Thanks for your help.

    Can you help me with this error I try to run your script but everytime i try I always getting this error

    Thanks!

    Pol

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2023-08-02T13:07:11+00:00

    Hi Pol

    I'm AnnaThomas and I'd happily help you with your question. In this Forum, we are Microsoft consumers just like yourself.

    Here is an example script that shows how you can use the Microsoft Graph SDK for PowerShell to bulk upload users from a CSV file:

    Install the Microsoft Graph SDK for PowerShell

    Install-Module -Name Microsoft.Graph

    Connect to the Microsoft Graph API

    Connect-MgGraph

    Import the CSV file

    $users = Import-Csv -Path "D:\O365\bulk2.csv"

    Iterate over each user in the CSV file

    foreach ($user in $users) { # Create a new user object $newUser = New-MgUser -DisplayName $user. DisplayName -GivenName $user. FirstName -Surname $user. LastName -UserPrincipalName $user. UserPrincipalName -PasswordProfile @{ ForceChangePasswordNextSignIn = $true; Password = $user. Password } -UsageLocation $user. UsageLocation

    Assign licenses to the new user

    New-MgUserLicense -UserId $newUser.Id -AddLicenses @{ SkuId = $user. AccountSkuId }
    

    }

    Learn more: https://learn.microsoft.com/graph/sdks/large-file-upload?tabs=csharp

    I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.

    Best Regards,

    AnnaThomas

    Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.

    Was this answer helpful?

    0 comments No comments