SharePoint Online: Export Access Requests Settings using PowerShell

Requirement: Export access requests settings for all sites in SharePoint Online.

SharePoint Online: PowerShell to Export Access Requests Settings (Email Address, Group Configuration)

To export access requests settings from all sites in the SharePoint Online tenant, use this PowerShell:

$TenantAdminURL = ""
$CSVPath = "C:\Temp\AcccessRequestData.csv"
$AccessRequestData= @()
#Function to Get access request Configuration for a SharePoint Online site
Function Get-PnPAccessRequestConfig
        [parameter(Mandatory = $true, ValueFromPipeline = $True)] $Web
    Try {
        Write-host -f Yellow "Getting Access Request Settings on:"$web.Url
            #Get Access Requests Configuration
            If($Web.RequestAccessEmail -ne [string]::Empty)
                #Get Access Request Email
                $AccessRequest = "Enabled"
                $EmailOrGroup = "Email"
                $AccessRequestConfig = $Web.RequestAccessEmail
                Write-host -f Green "`tAccess Requests is '$AccessRequest', Set to '$EmailOrGroup' as '$AccessRequestConfig'!"
            Elseif($Web.UseAccessRequestDefault -eq $true)
                #Get Associated Owners Group
                $AccessRequest = "Enabled"
                $EmailOrGroup = "Default Owner Group"
                #Get the Default Owners Group of the site
                $OwnersGroup = Get-PnPGroup -AssociatedOwnerGroup
                $AccessRequestConfig = $OwnersGroup.Title
                Write-host -f Green "`tAccess Requests is '$AccessRequest', Set to '$EmailOrGroup' as '$AccessRequestConfig'!"
                #Access Request is Disabled!
                $AccessRequest = "Disabled"
                $EmailOrGroup = [string]::Empty
                $AccessRequestConfig = [string]::Empty
                Write-host -f Green "`tAccess Requests is $AccessRequest!"
            $AccessRequest = "Inherits from Parent"
            $EmailOrGroup = [string]::Empty
            $AccessRequestConfig = [string]::Empty
            Write-host -f Yellow "`tWeb inherits permissions from the parent!"$web.Url

        #Collect Data
        $AccessRequestData+= New-Object PSObject -Property ([ordered]@{
                WebURL  = $Web.URL
                AccessRequest = $AccessRequest
                EmailOrGroup = $EmailOrGroup
                AccessRequestConfig =  $AccessRequestConfig
           #Export Data to CSV
            $AccessRequestData | Export-Csv -Path $CSVPath -NoTypeInformation -append

    Catch {
        write-host "`tError Getting Access Requests: $($_.Exception.Message)" -foregroundcolor Red
#Connect to Admin Center
$Cred = Get-Credential
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred

If(Test-Path $CSVPath) { Remove-Item $CSVPath }

#Get All Site collections - Exclude: Seach Center, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$SitesCollections = 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 $SitesCollections)
    #Connect to site collection
    Connect-PnPOnline -Url $Site.Url -Credentials $Cred
    #Call the Function for Root Web and all Subwebs
    Get-PnPSubWeb -IncludeRootWeb -Recurse -Includes HasUniqueRoleAssignments, RequestAccessEmail, UseAccessRequestDefault | ForEach-Object { Get-PnPAccessRequestConfig $_ }

This PowerShell script gets the inventory of all access request settings and exports it to a CSV file.

sharepoint online access requests

Related posts:

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

3 thoughts on “SharePoint Online: Export Access Requests Settings using PowerShell

  • Excellent information. How can we get similar information for SharePoint 2016 on premise server?

  • Excellent, agree!


Leave a Reply

Your email address will not be published. Required fields are marked *