Add external users in a Site using PowerShell with MFA

Tanmoy Das 66 Reputation points
2022-11-06T05:34:58.637+00:00

Hi,

I need a ps script to add external users in SP site with MFA. Can anyone please share if they have one working?

Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,075 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rijwan Ansari 746 Reputation points MVP
    2022-11-06T07:44:10.663+00:00

    HI,

    You can try below script:

    #Parameters  
    $AdminCenterURL="https://Crescent-admin.sharepoint.com"  
       
    #Setup Credentials to connect  
    Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)  
       
    #add guest user to sharepoint online site  
    Add-SPOUser -Group "Marketing Visitors" -LoginName "George@NationalAquarium.com" -Site "https://Crescent.sharepoint.com/sites/Marketing"  
    

    https://www.sharepointdiary.com/2019/05/add-external-user-to-sharepoint-online-using-powershell.html


  2. Haoyan Xue_MSFT 21,401 Reputation points Microsoft Vendor
    2022-11-07T02:55:13.677+00:00

    Hi @Tanmoy Das ,
    You can try below script to add External User to SharePoint Online Site:

    #Site Variables  
    $SiteURL = "https://domian.sharepoint.com/sites/xyzax-version1/"  
    $GroupName = "group2"  
    $ExternalUserEmail = "xxx@xx.com"  
       
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
       
    #PowerShell to Add External User to group  
    Add-PnPGroupMember -Identity $GroupName -EmailAddress $ExternalUserEmail -SendEmail  
    

    The running result is as shown below:
    257706-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.