Can I add External users to a SharePoint group using (PnP) Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-68246%22%20slang%3D%22en-US%22%3ECan%20I%20add%20External%20users%20to%20a%20SharePoint%20group%20using%20(PnP)%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-68246%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnyone%20know%20how%20to%20add%20external%20users%20to%20a%20group%20in%20an%20Office%20365%20Tenancy%20using%20(PnP)%20Powershell%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(I%20have%20about%202500%20external%20users%20to%20add)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENigel%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-68246%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-292877%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20I%20add%20External%20users%20to%20a%20SharePoint%20group%20using%20(PnP)%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-292877%22%20slang%3D%22en-US%22%3E%3CP%3EAnd%20don't%20forget%20that%20you%20need%20to%20elevate%20a%20member%20to%20the%20status%20of%20an%20owner%20(and%20vice%20versa)%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3EAdd-UnifiedGroupLinks%20-Identity%20%22Teamsite%20Test%22%20-LinkType%20Members%20-Links%26nbsp%3Bjohn%40doe.com%3CBR%20%2F%3EAdd-UnifiedGroupLinks%20-Identity%20%22Teamsite%20Test%22%20-LinkType%20Owners%20-Links%20%3CSPAN%3Ejohn%40doe.com%3C%2FSPAN%3E%3CBR%20%2F%3ERemove-UnifiedGroupLinks%20-Identity%20%22Teamsite%20Test%22%20-LinkType%20Owners%20-Links%20%3CSPAN%3Ejohn%40doe.com%3C%2FSPAN%3E%20-Confirm%3A%24false%3CBR%20%2F%3ERemove-UnifiedGroupLinks%20-Identity%20%22Teamsite%20Test%22%20-LinkType%20Members%20-Links%20%3CSPAN%3Ejohn%40doe.com%3C%2FSPAN%3E%20-Confirm%3A%24false%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3EYou%20add%20a%20new%20member%20and%20then%20you%20can%20set%20this%20contact%20as%20an%20owner.%20Works%20perfectly.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-292873%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20I%20add%20External%20users%20to%20a%20SharePoint%20group%20using%20(PnP)%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-292873%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F136174%22%20target%3D%22_blank%22%3E%40Nils%20K%C3%BClper%3C%2FA%3E%20-%20that%20is%20great%20!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-292870%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20I%20add%20External%20users%20to%20a%20SharePoint%20group%20using%20(PnP)%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-292870%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20add%20Users%20to%20O365%20Groups%20with%20this%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CFONT%3E%24Session%20%3D%20New-PSSession%20-ConfigurationName%20Microsoft.Exchange%20-ConnectionUri%20%3CA%20href%3D%22https%3A%2F%2Foutlook.office365.com%2Fpowershell-liveid%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foutlook.office365.com%2Fpowershell-liveid%2F%3C%2FA%3E%20-Credential%20%24userCredential%20-Authentication%20Basic%20-AllowRedirection%3CBR%20%2F%3EImport-PSSession%20%24Session%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3ESet-DistributionGroup%20%22TeamsiteTest%22%20-ManagedBy%20%22nilsb%40dudde.team%22%20-BypassSecurityGroupManagerCheck%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3EAdd-UnifiedGroupLinks%20-Identity%20%22Teamsite%20Test%22%20-LinkType%20Members%20-Links%20john%40doe.com%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-68278%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20I%20add%20External%20users%20to%20a%20SharePoint%20group%20using%20(PnP)%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-68278%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20unsure%20from%20your%20question%20that%20you%20are%20trying%20to%20add%20external%20users%20to%20SharePoint%20group%20%2F%20Office%20365%20group.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20it%20was%20SharePoint%20group%20you%20can%20use%20below%20PnP.%20Please%20note%20that%20the%20external%20users%20need%20to%20be%20present%20in%20Azure%20AD%20before%20executing%20this%20script.%3C%2FP%3E%3CPRE%3EAdd-PnPUserToGroup%20-LoginName%20user%40company.com%20-Identity%20'Marketing%20Site%20Members'%3C%2FPRE%3E%3CP%3EIf%20it%20was%20Office%20365%20Groups%2C%20AFAIK%20there%20is%20no%20PowerShell%20to%20add%20external%20users%20to%20the%20group.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Hi

 

Anyone know how to add external users to a group in an Office 365 Tenancy using (PnP) Powershell ?

 

(I have about 2500 external users to add)

 

Regards

 

Nigel

4 Replies

I am unsure from your question that you are trying to add external users to SharePoint group / Office 365 group.

 

If it was SharePoint group you can use below PnP. Please note that the external users need to be present in Azure AD before executing this script.

Add-PnPUserToGroup -LoginName user@company.com -Identity 'Marketing Site Members'

If it was Office 365 Groups, AFAIK there is no PowerShell to add external users to the group.

You can add Users to O365 Groups with this code:

 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $userCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Set-DistributionGroup "TeamsiteTest" -ManagedBy "nilsb@dudde.team" -BypassSecurityGroupManagerCheck
Add-UnifiedGroupLinks -Identity "Teamsite Test" -LinkType Members -Links john@doe.com

And don't forget that you need to elevate a member to the status of an owner (and vice versa) like this:

 

Add-UnifiedGroupLinks -Identity "Teamsite Test" -LinkType Members -Links john@doe.com
Add-UnifiedGroupLinks -Identity "Teamsite Test" -LinkType Owners -Links john@doe.com
Remove-UnifiedGroupLinks -Identity "Teamsite Test" -LinkType Owners -Links john@doe.com -Confirm:$false
Remove-UnifiedGroupLinks -Identity "Teamsite Test" -LinkType Members -Links john@doe.com -Confirm:$false

 

You add a new member and then you can set this contact as an owner. Works perfectly.