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 "ClassABC@acme.org" (without the dot) and through the script I add the students to the group. I'm using PNP.Powershell. One example:

Add-UnifiedGroupLinks –Identity "ClassABC@acme.org" –LinkType "Members" –Links "Student.19912@acme.org"

The problem is this group "ClassABC@acme.org" 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 "ClassABC@acme.orgt" -Identity "Visitors of Class.ABC"
Remove-PnPGroupMember -LoginName "ClassABC@acme.org" -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! ;)

0

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

Example:

Set-PnPWebPermission -User "ClassABC@acme.org" -AddRole "Visitor"

Or

Add-SPOUser -Site https://hasai.sharepoint.com/sites/Team -LoginName ClassABC@acme.org -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 ClassABC@acme.org -Group " Class.ABC Visitors"
1
  • You're right! The Add-PNPGroupMember was wrong as you said! – Vítor Verdura Feb 28 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 – Vítor Verdura Feb 26 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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