首先,我是网站集中的全局管理员和网站集管理员,我正在尝试以下代码。
错误的西班牙语,但它说Access拒绝
Failed to delete receiver - error: Exception calling "ExecuteQuery" with "0" argument(s): "Acceso denegado. No tiene el permiso
necesario para realizar esta acción o tener acceso a este recurso."
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
代码是:
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$webUrl = Read-Host -Prompt "HTTPS URL for your SP Online 2013 site" #"https://michaelbl.sharepoint.com"
$username = Read-Host -Prompt "Email address for logging into that site" #michaelbl@michaelbl.onmicrosoft.com"
$password = Read-Host -Prompt "Password for $username" -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext("https://mysite.sharepoint.com/sites/dev.site.intranet")
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$list = $ctx.Web.Lists.GetByTitle("Clientes")
$ctx.Load($list)
$ctx.ExecuteQuery()
$eventReceivers = $list.EventReceivers
$ctx.Load($eventReceivers)
$ctx.ExecuteQuery()
$specifiedEr = $null
try
{
foreach ($er in $eventReceivers)
{
if ($er.ReceiverName -eq "CLIENTES_ITEMADDED")
{
$specifiedEr = $er
}
}
if ($specifiedEr -ne $null -and !$specifiedEr.ServerObjectIsNull.Value)
{
$specifiedEr.DeleteObject()
$ctx.ExecuteQuery()
Write-Host "Receiver deleted successfully"
}
else
{
Write-Error "Failed to find receiver with name '$receiverName'"
}
}
catch
{
Write-Error "Failed to delete receiver - error: $_"
}