Share via


Add permissions to all subsites in site collection

Question

Wednesday, January 3, 2018 3:07 PM

I have a need to apply a group permissions to every subsite in a site collection.  The subsites all have unique permissions and there are a lot of them.  Is this possible with a shell script or something similar?   

All replies (4)

Thursday, January 4, 2018 3:57 AM ✅Answered

Hi GrayreverandSoftwareGuy,

For your request, I suggest you using SharePoint PnP PowerShell Online.

Firstly, connect SharePoint Online site using command below:

Connect-PnPOnline -Url https://domain.sharepoint.com

Run the command below to get subsites and grant a group permission:

Function Get-Subsites() {  
    $subwebs= Get-PnPSubWebs -Recurse   
     foreach ($Subweb in $subwebs)  
    {  
       Set-PnPGroupPermissions -Identity 'spgroup1' -web $Subweb -AddRole Contribute
    }  
}   
Get-SubSites

Best regards,

Grace Wang

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Thursday, January 4, 2018 9:28 PM

Hi Grace,

Thank you for the reply.  I tried your steps but I keep getting an error that my group cannot be found.  I know it's a valid group though.  I've tried with others too so I wonder if I'm missing a step somewhere.  


Friday, January 5, 2018 6:29 AM

Hi GrayreverandSoftwareGuy,

The group needs to be SharePoint Group.

Since it’s not feasible to grant AD security group/office 365 group  permission though SharePoint management shell,  I suggest you adding the group to SharePoint group and run the command above.

Best regards,

Grace Wang

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Friday, January 5, 2018 5:36 PM

Thanks Grace, that worked!