Quantcast
Channel: SharePoint Pals - PowerShell
Viewing all articles
Browse latest Browse all 31

PowerShell script to set user email in the access request settings on Modern SharePoint Site

$
0
0


In this article, let us see how to change or add the user to access request list

The access request feature allows people to request access to content that they do not currently have permission to see. As a site owner, you can configure the feature to send you mail when someone requests access to a site. You can then choose whether to approve or decline their request. If you approve the request, you can also specify the specific level of permission you’d like to assign to a user.

 #Load SharePoint CSOM Assemblies  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")  #Set Variables for Site URL  $SiteURL= "https://xxx.sharepoint.com/sites/xxx/"  $AccessReqEmail="xxx@xxx.onmicrosoft.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 = $False  $web.AssociatedMemberGroup.Update()  $Web.Update()  $Ctx.ExecuteQuery()  Write-Host "Access Request Settings applied"  }  Catch {  } 

Hope this helps!

Thanks


Viewing all articles
Browse latest Browse all 31

Trending Articles