I have a remote event receiver which is attached to a list. so i want to remove it, but when i try this PnP script using the Office 365 admin:-

Remove-PnPEventReceiver -List "Our Project"  -Identity "ProjectRER"

I got the following exception:-

Remove-PnPEventReceiver : Access denied. You do not have permission to perform this action or access this resource.

also based on this link https://techcommunity.microsoft.com/t5/sharepoint-developer/problem-in-deleting-remote-event-receiver-in-sharepoint/m-p/31583 i tried the following powershel:-

function Get-SPOListEventreceivers
param (

  $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)

} catch [Net.WebException] 

            Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red


 Write-Host "Found " $recevery.Count " receivers in " $lista.Title


Write-Host "receiver removed"

 catch [Net.WebException] 
  Write-Host "Failed to delete the receiver" $_.Exception.Message.ToString() -ForegroundColor Red


# Paths to SDK. Please verify location on your computer.
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

# Insert the credentials and the name of the admin site
$password = "$xxxx" 
$url = "https://xxxx.sharepoint.com/sites/S046WW16776"
$AdminPassword=Read-Host -Prompt "Password" -AsSecureString
$ListTitle="Our Project"

Get-SPOListEventreceivers -Username $Username -AdminPassword $AdminPassword -Url $Url -ListTitle $ListTitle -EventReceiverGUID $EventreceiverGUID

but i got this error also:-

Exception calling "ExecuteQuery" with "0" argument(s): "Access denied. You do not have permission to perform this
action or access this resource."
At line:42 char:1
+ $ctx.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ServerUnauthorizedAccessException

So can anyone advice on this please?

  • Remember, a user that has the SharePoint Admin role does not automatically have any permissions to any of the sites. You may need to explicitly make that account a site collection admin for the site you are trying to manage RER's. – willman Feb 12 at 11:39
  • @willman the office 365 admin is explicitly define as the site collection admin – SharePoint TestDev Feb 12 at 13:14
  • Of the S046WW16776 site? – willman Feb 12 at 15:12
  • Instead of setting credentials on a new context, try executing Connect-SPOService with the credentials parameter, the call $ctx = get-spocontext to get the authenticated context. – willman Feb 12 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.