Can I bulk invite guest users with attributes i.e. Department, into Azure?

48408137 0 Reputation points
2024-01-25T09:03:58.5133333+00:00

I am looking to invite a large batch of users to Azure using the Bulk invite area but would like to provide further information. I would like to add First Name, Last Name, Company, Department, Employee ID and potentially the Usage Location. Is there a way of doing this for large amounts of users?Currently the bulk invite did not provide areas for this additional data.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
18,562 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 12,200 Reputation points
    2024-01-25T14:37:57.1666667+00:00

    you can prepare a PowerShell script to accomplish this task

    First, prepare a .csv file with essential user information like FirstName, LastName, and EmailAddress.

    Use PowerShell commands to connect to MS Graph and upload the .csv file.

    Guest user accounts are created via an “Invitation.” You can suppress the default invitation email with -SendInvitationMessage:$false.

    $csv = Import-Csv -Path "<Path to your CSV file>"
    # we assume you have columns: FirstName,LastName,EmailAddress
    
    Connect-MgGraph -Scopes User.Invite.All,User.ReadWrite.All,Directory.ReadWrite.All
    
    foreach ($user in $csv) {
    
        $userEmail = $user.EmailAddress
        $userName = "$($user.FirstName) $($user.LastName)"
    
        $existingUser = Get-MgUser -Filter "mail eq '$userEmail'"
        if ($null -eq $existingUser) {
           
            $invitation = @{
                InvitedUserEmailAddress = $userEmail
                InvitedUserDisplayName = $userName
                InviteRedirectUrl = "https://www.xxx.com"
                SendInvitationMessage = $true
            }
    
            New-MgInvitation @invitation
            Write-Host "Invitation sent to $userName ($userEmail)"
        } else {
            Write-Host "User $userName ($userEmail) already exists."
        }
    }
    
    Disconnect-MgGraph
    
    

    you can check the Graph API documentation from Azure Site