Bulk Addition of External Users to Sharepoint online Site

We got a  requirement to add hundreds of external users to Sharepoint Online site which is kind of a daunting task if needs to be done manually.PowerShell and CSOM came to rescue us , We have built a script that will read user email addresses from users.txt file and will send the

 
 
 
 
 
(0)
65 times
Add to favorites
Office 365
10/30/2019
E-mail Twitter del.icio.us Digg Facebook
  • How about adding a user to a SiteGroup?
    3 Posts | Last post December 27, 2019
    • So, the only issue I have with this is the user is not added to a SiteGroup.
      
      How do I add them to a SiteGroup, the other is harder to manage.
    • There is another approach, creating a azure ad group and populating that via script and inviting from there.
      
      New-AzureADMSInvitation  -InvitedUserEmailAddress vikas@labtest.com -InviteRedirectURL https://myapps.azure.com -SendInvitationMessage $false
      
      #Connect to AAD as admin prior to running
      
      $messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo
        
      #Message Content
      $messageInfo.customizedMessageBody = "Please accept the invitation."
      
      #Security Group users are to be added to
      $group = get-azureadgroup -SearchString AZureADgrouptest
      
      #Address presented to the users in their welcome email
      $url = "https://company.sharepoint.com/sites/INtSite"
      
      #List of users to be imported
      $invitations = get-content .\users.txt
      
      #Add users as guests with Azure AD and then add them as members to the relevant security group
      $invitations | foreach-object { $result= New-AzureADMSInvitation `
            -InvitedUserEmailAddress $_ `
            -InviteRedirectUrl $url `
            -InvitedUserMessageInfo $messageInfo `
            -SendInvitationMessage $true
         $userid = $result.InvitedUser.Id
         Add-AzureADGroupMember -objectid $group.objectid -RefObjectId $userid
         write-host "Processing...$_" -foregroundcolor green
         }
    • This can be tackled another way by creating azure ad group and sending invitations from there
      
      New-AzureADMSInvitation  -InvitedUserEmailAddress vikas@labtest.com -InviteRedirectURL https://myapps.azure.com -SendInvitationMessage $false
      
      #Connect to AAD as admin prior to running
      
      $messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo
        
      #Message Content
      $messageInfo.customizedMessageBody = "Please accept the invitation."
      
      #Security Group users are to be added to
      $group = get-azureadgroup -SearchString AZureADgrouptest
      
      #Address presented to the users in their welcome email
      $url = "https://company.sharepoint.com/sites/INtSite"
      
      #List of users to be imported
      $invitations = get-content .\users.txt
      
      #Add users as guests with Azure AD and then add them as members to the relevant security group
      $invitations | foreach-object { $result= New-AzureADMSInvitation `
            -InvitedUserEmailAddress $_ `
            -InviteRedirectUrl $url `
            -InvitedUserMessageInfo $messageInfo `
            -SendInvitationMessage $true
         $userid = $result.InvitedUser.Id
         Add-AzureADGroupMember -objectid $group.objectid -RefObjectId $userid
         write-host "Processing...$_" -foregroundcolor green
         }