Update the request access email in multiple SharePoint Online sites

Background

Recently I had a request to update 50 plus SharePoint Online sites with a group email address so that this mailbox received all site access requests.  This group was being used as the owners of the SharePoint sites and as it was a group they had not been receiving the access requests. As a result we decided we wanted to forward these requests to the group mailbox.   Using the resources from Microsoft Docs I was able to set the request access email in a SharePoint site, using PowerShell.  

Using the guidance command provided in Microsoft Docs I was able to create a PowerShell script and added a step to repeat this on multiple sites by importing a spreadsheet (CSV) with the site addresses.

If had done this manually it would have taken around a day to go to each site and set. Using the script in a matter of minutes the job was done and I was able to focus on other tasks.  I did a few random spot checks to ensure it worked. 

What you need to get started

  • Ensure you have installed the relevant PowerShell modules are required to run the script
  • SharePoint Admin rights to successfully run the commands 
  • Review the Microsoft Docs guidance: Set-PnPRequestAccessEmails

    Steps to replicate

    These are the steps to create and run the script to update all SharePoint sites access requests:
    1. Create a .csv file
    2. Identify your mail address
    3. Update and run the PowerShell script

    Create a .csv file

    If like me you have a number of site you want to set the access requests, then create a .csv file in Excel. 
    • In Cell A1 add the title SiteCollection. 
    • Add the Urls for each site underneath (see example below). 
    • Save the Excel file as .csv

    Identify your mail address

    Identify the mail address the access requests are going to be directed, if a user clicks to request access to the SharePoint site.  

    I had been requested to do this for a group mailbox address rather than an individual. This worked successfully but if you wanted this could also be a specific persons email address to receive the access request. 

    Best practice suggestion would be to use a group mailbox to solve any issues of absence or the person leaving the business.

    Update and run the script

    Below is an example of the script I used to achieve the updating of the request access email in multiple SharePoint Online sites.

    # Variable: Amend these variables to suit 
    $adminSiteUrl = "https://COMPANY-admin.sharepoint.com"
    $AccessReqEmail ="JOHN.SMITH@company.com"
    $csvFile ="C:\FILE LOCATION\sites.csv"
    # Connect to SPO admin Centre
    Connect-PnPOnline -Url $adminSiteUrl
    # Import sites from .csv
    $table = Import-Csv $csvFile -Delimiter ","
    # Using csv the script runs through each row to connect to each Site
    foreach ($row in $table) {
    Write-Host $row.SiteCollection
    Connect-PnPOnline -Url $row.SiteCollection -UseWebLogin
    # Sets the Access Request Email using the variable
    Set-PnPRequestAccessEmails -Emails $AccessReqEmail
    }
    # Lets you know script has completed
    Write-Host "Access Request updated" -ForegroundColor Green

    Update the variables shown in the above script (see red text) then run using PowerShell. The script will : 
    • Connect to the tenant, 
    • Import the spreadsheet 
    • Lookup the SiteCollection column to find the site address (Url)
    • Then run the Set-PnPRequestAccessEmails command on all sites listed. 
    Depending on the number of sites it may take a few minutes for the script to complete. I did a few spot checks on each site to confirm even though I had no errors. 

    Conclusion 

    This script probably saved me close to a days manual work and allowed me to focus on other more important tasks. I hope that it helps save you some time too. 

    Popular posts from this blog

    Review of the Champion Management Platform App

    Review of Microsoft 365 Learning Pathways

    Review of the Microsoft Teams Adoption Bot