0

Thanks for you time reading this. We are a Technical School that's using Sharepoint 365 as way to collect files and resources. We have to open a Sharepoint to each class and I'm compiling a Powershell script to be easier... When added a Site lets say "Class.ABC", the system also creates a group called "[email protected]" (without the dot) and through the script I add the students to the group. I'm using PNP.Powershell. One example:

Add-UnifiedGroupLinks –Identity "[email protected]" –LinkType "Members" –Links "[email protected]"

The problem is this group "[email protected]" is put in the "Members" group of the site by default, and therefore with contribute permissions. I want to change this group to "Visitors" of the site.

I've try this:

Add-PnPGroupMember -LoginName "[email protected]" -Identity "Visitors of Class.ABC"
Remove-PnPGroupMember -LoginName "[email protected]" -Identity "Members of Class.ABC"

But it didn't work as they work only with users not groups!

Is there any way to accomplish this?

Thanks a lot for your kind help. I'm not very good at Powershell, so please be gentle! ;)

2 Answers 2

0

The cmdlet you should use is Set-PnPWebPermission or Add-SPOUser.

Example:

Set-PnPWebPermission -User "[email protected]" -AddRole "Visitor"

Or

Add-SPOUser -Site https://hasai.sharepoint.com/sites/Team -LoginName [email protected] -Group "ClassABC Visitors"

References: Set-PnPWebPermission. / Add a user to other site collection groups.


NOTE:

The cmdlet Add-UnifiedGroupLinks works for managing Microsoft 365 group members only.

And the script for Add-PnPGroupMember should be

Add-PnPGroupMember -LoginName [email protected] -Group " Class.ABC Visitors"
1
  • You're right! The Add-PNPGroupMember was wrong as you said! Feb 28, 2021 at 22:11
0

Since you are adding users to a Microsoft 365 Group, I'm afraid you may not be able to move that group from its current SPO Members group to Visitors group. However, you could change the default SPO Members group's permission from Edit to Read using the following script.

Reference doc.microsoft

Set-PnPGroup -Identity 'My Site Members' -SetAssociatedGroup Visitors

You can also accomplish the same manually. For details, visit this link

1
  • Thanks Matiur! I don't want to change the permissions as I use the group for the Teacher who have the Edit permissions Feb 26, 2021 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.