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

Manimekalai
 
Technology Specialist
November 8, 2018
 
Rate this article
 
Views
3156

 

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.

Clear-host
  
 Write-Output -msg "Start : Module loading Process"
 $modulePath = "C:Program Files (x86)SharePointPnPPowerShellOnlineModulesSharePointPnPPowerShellOnline"
 import-module ($modulePath + "SharePointPnPPowerShellOnline.psd1")
 Add-Type -Path ($modulePath + "SharePointPnP.PowerShell.Online.Commands.dll")
 Add-Type -Path ($modulePath + "Microsoft.SharePoint.Client.dll")
 Add-Type -Path ($modulePath + "Microsoft.SharePoint.Client.Runtime.dll")
 Add-Type -Path ($modulePath + "Microsoft.Online.SharePoint.Client.Tenant.dll")
 Write-Output -msg "End : Module loading Process"
  
 $cred = Get-Credential
 $csv = import-csv -Path "D:ScriptsSiteInput.csv"
 Clear-Content "D:SiteCreationLog.txt"
 try
 {
 foreach($value in $csv)
 {
 $ParentURL=$value.ParentSiteURL
 $TargetURL=$value.URL
 $WebTemplate=$value.Template
 $Title=$value.Title
 $Description=$value.Description
 $URL= $TargetURL -replace $ParentURL+'/'
 if($WebTemplate -eq "Team")
 {  
     #Connect to Site Collection       
     Connect-PnPOnline -Url $ParentURL -Credentials $cred
     #Create sub web with unique permissions
     New-PnPWeb -Title $Title -Url $URL -Description $Description -BreakInheritance -InheritNavigation -Template "STS#3"
     Disconnect-PnPOnline
     Connect-PnPOnline -Url $TargetURL -Credentials $cred
     $owner = (Get-PnPContext).Credentials.UserName
  
     #Create default groups for the new web
     $OwnerGroupName=$URL+" Owners"
     $MemberGroupName=$URL+" Members"
     $VisitorGroupName=$URL+" Visitors"
  
     $ownerGroup = New-PnPGroup -Title $OwnerGroupName -Owner $owner
     Set-PnPGroup -Identity $ownerGroup -SetAssociatedGroup Owners
     Set-PnPGroupPermissions -Identity $ownerGroup -AddRole "Full Control"
        
     $memberGroup = New-PnPGroup -Title $MemberGroupName -Owner $owner
     Set-PnPGroup -Identity $memberGroup -SetAssociatedGroup Members
     Set-PnPGroupPermissions -Identity $memberGroup -AddRole "Edit"
  
     $visitorGroup = New-PnPGroup -Title $VisitorGroupName -Owner $owner
     Set-PnPGroup -Identity $visitorGroup –SetAssociatedGroup Visitors
     Set-PnPGroupPermissions -Identity $visitorGroup -AddRole "Read"
      
     $TargetURL+" PASS" | Out-File -FilePath D:SiteCreationLog.txt -Append
 }
 else
 {
     Write-Error "Invalid Template Name"
     $TargetURL+" Invalid Template Name"| Out-File -FilePath D:SiteCreationLog.txt -Append
 }
 }
 }
 catch
 {
 Write-Output $_.Exception.Message 
 $TargetURL+" "+$_.Exception.Message | Out-File -FilePath D:SiteCreationLog.txt -Append
 }

Hope this helps!

Thanks

Category : PowerShell

Author Info

Manimekalai
 
Technology Specialist
 
Rate this article
 
Having 6 years of experience in design and development of SharePoint applications, Mani has expertise in developing applications using Office 365, SharePoint 2013 & 2010, SPFX, SP Designer Workflows, Visual ...read more
 

Leave a comment