Share via

Assign permissions

christieA-9828 140 Reputation points
2025-01-31T02:50:33.9666667+00:00

Is there a way to assign a user access to all SharePoint sites at once? What permission settings are available for this purpose?

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

Answer accepted by question author

Emily Du-MSFT 51,986 Reputation points Microsoft External Staff
2025-01-31T08:42:54.2833333+00:00

You could use PowerShell to assign a user access to all SharePoint sites.

#Parameters
$TenantAdminURL="https://tenant-admin.sharepoint.com"
$UserAccount = "******@M365x68721329.onmicrosoft.com"
 
#Get Credentials to Connect
$Cred = Get-Credential
 
Try {
    #Connect to Tenant Admin
    Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred
#Get All Site collections - Exclude: Seach Center, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$Sites = Get-PnPTenantSite | Where -Property Template -NotIn ("SRCHCEN#0", "REDIRECTSITE#0","SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")
#Loop through each Site Collection
ForEach ($Site in $Sites)
{
    Try {
        #Connect to the Site
        Connect-PnPOnline -Url $Site.Url -Credentials $Cred
#Permission Level to Grant
        $PermissionLevel = "Contribute"
#grant permission Level to the user
        Set-PnPWebPermission -User $UserAccount -AddRole $PermissionLevel
}
    Catch {
        write-host -f Red "Error Adding User to the Site: $($Site.URL)" $_.Exception.Message
    }
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}

If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.