kwizcom banner advertisement

SharePoint Online: Configure Access Request Email Settings using PowerShell

Access request settings in SharePoint Online
Access Request feature in SharePoint online allows people to request access to content that they do not have permission. It also allows members of the site to send invitations to users who have no permission. Once the invitations are sent, Site owner should approve it from Site settings >> Access requests and invitations. If you change these settings on the Site Collection level, then new sub sites doesn’t inherit.

How to Set SharePoint Online Access Request Email? To configure access request email settings in SharePoint online, Go to
  • Site Settings >> Site Permissions >> Access Requests Settings 
  • This takes you to SharePoint online access request page >> Update access request email and hit OK to save your changes.sharepoint online access request settings powershell
Please note, SharePoint online access request email Site Settings must be configured at each site level. Lets see SharePoint Online PowerShell to set access request email.


Set SharePoint online access request settings using PowerShell
Use this PowerShell script to update SharePoint online access request email.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
#Set Variables for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$AccessReqEmail="SharePointSupport@crescent.com"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the current settings
    $Web = $Ctx.Web
    $Ctx.Load($web.AllProperties)
    $web.RequestAccessEmail
    $Ctx.ExecuteQuery()

    #Set Access request Email
    $Web.RequestAccessEmail =$AccessReqEmail
    #Member settings
    $Web.MembersCanShare = $True
    $web.AssociatedMemberGroup.AllowMembersEditMembership = $True
    $web.AssociatedMemberGroup.Update()

    $Web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error configuring Access request settings!" $_.Exception.Message
}
This sets SharePoint Online access request settings with PowerShell.

Disable access request in SharePoint Online:
To disable access request, simply clear the Email value!
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
#Set Variables for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #disable Access request
    $Web = $Ctx.Web
    $Web.RequestAccessEmail = ""
    $Web.MembersCanShare = $False    
    $web.AssociatedMemberGroup.AllowMembersEditMembership = $False
    $web.AssociatedMemberGroup.Update()
    $Web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error disabling Access request settings!" $_.Exception.Message
}
SharePoint Online: Configure Access Request Email Settings using PowerShell SharePoint Online: Configure Access Request Email Settings using PowerShell Reviewed by Salaudeen Rajack on 8:42 PM Rating: 5

3 comments:

  1. Hi,

    Can we Set SharePoint online access request settings using PowerShell for all sites?
    Email id will be Service Desk email?

    Could you please help on this requirement.

    Thank You.

    ReplyDelete
    Replies
    1. Can we configure SharePoint online access request settings for all modern site collections?

      Not for one site collection.

      Thank You.

      Delete

Please Login and comment to get your questions answered!

Powered by Blogger.