Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-PnPGroupMember does not work for "Everyone except external users" #202

Closed
1 of 6 tasks
DmitryVorobyov opened this issue Feb 1, 2021 · 2 comments
Closed
1 of 6 tasks

Comments

@DmitryVorobyov
Copy link

Reporting an Issue or Missing Feature

Please confirm what it is that your reporting

Bug: Add-PnPGroupMember does not work for "Everyone except external users". The code below used to work with Add-PnPUserToGroup cmdlet, it throws an error now.

Expected behavior

"Everyone except external users" is added to the specified SharePoint group (e.g. Visitors)

Actual behavior

Error message:
Add-PnpGroupMember: Exception has been thrown by the target of an invocation.

Add-PnpUserToGroup_Everyone_Error

Steps to reproduce behavior

Connect-PnPOnline $siteUrl -UseWebLogin

$ctx = Get-PnPContext
$web = Get-PnPWeb -Includes WebTemplate, Configuration

$Principal = [Microsoft.SharePoint.Client.Utilities.Utility]::ResolvePrincipal($ctx, $web, "Everyone except external users", "All", "All", $Null, $True)
$ctx.ExecuteQuery()
$everyoneLoginName = $Principal.Value.LoginName

Add-PnPGroupMember -LoginName $everyoneLoginName -Identity $web.AssociatedVisitorGroup

What is the version of the Cmdlet module you are running?

1.2.0

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@DmitryVorobyov DmitryVorobyov added the bug Something isn't working label Feb 1, 2021
@erwinvanhunen erwinvanhunen changed the title [BUG] Add-PnPGroupMember does not work for "Everyone except external users" Add-PnPGroupMember does not work for "Everyone except external users" Feb 1, 2021
@erwinvanhunen erwinvanhunen removed the bug Something isn't working label Feb 1, 2021
@erwinvanhunen
Copy link
Member

Behind the scenes we are not using CSOM anymore in this cmdlet to acquire the correct group, for that reason we require the group to have the ID property loaded before we can add a member to it.

In a more 'powershell' way, this works with the release you have installed:

$user = Get-PnPUser | ?${$_.Title -eq "Everyone except external users"} # but your approach to find the principal will work too
$group = Get-PnPGroup -AssociatedVisitorGroup
Add-PnPGroupMember -Login $user.LoginName -Group $group

We will merge an update today which will actually resolve the id of the group if not specified before we try to add the user to group. This change will be available in release 1.2.11-nightly.

erwinvanhunen added a commit that referenced this issue Feb 1, 2021
@DmitryVorobyov
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants