Assign permissions

christieA-9828 120 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?

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,241 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 49,461 Reputation points Microsoft Vendor
    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 = "admin@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.

    0 comments No comments

Your answer

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