当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:修复“远程服务器返回错误:(403) 禁止。” PowerShell 中的错误

作者:精品下载站 日期:2024-12-14 15:02:52 浏览:15 分类:玩电脑

SharePoint Online:修复“远程服务器返回错误:(403) 禁止。” PowerShell 中的错误


错误:使用“0”参数调用“ExecuteQuery”时出现异常:“远程服务器返回错误:(403) 禁止。”在 SharePoint Online 的 PowerShell 脚本中。

[玩转系统] SharePoint Online:修复“远程服务器返回错误:(403) 禁止。” PowerShell 中的错误

SharePoint Online PowerShell 中禁止的 403 问题排查清单:

“远程服务器返回错误:(403) 禁止。”使用 PowerShell 连接到 SharePoint Online 时可能会发生错误。此错误通常表示您用于连接到站点的凭据不正确,或者用户帐户没有足够的权限来访问该站点。您可以尝试以下几种方法:

按照此清单解决 SharePoint Online PowerShell 中的 ExecuteQuery 403 禁止错误。

  1. 您可能提供了另一个租户的凭据,这最终会出现此错误消息(与多个租户合作时会发生这种情况!)因此请确保 URL 和凭据正确。
  2. 您的客户端计算机上可能缺少 SharePoint Online 客户端组件 SDK。确保您安装了最新版本,并且引用的 DLL 路径正确。
  3. 您可能正在尝试访问您无权访问的网站! 通过浏览来验证您对该网站的访问权限。拥有租户管理员或 SharePoint Online 管理员角色不会自动获得对 SharePoint 网站的访问权限。您必须将自己明确添加到网站:如何使用 PowerShell 将网站集管理员添加到 SharePoint Online?
  4. 该网站可能处于锁定状态!您可以检查锁定状态并解锁:如何锁定/解锁 SharePoint Online 中的网站?
  5. 根据租户的条件访问策略,您可能需要在组织网络中使用合规设备。
  6. 您传递的凭据必须属于“SharePointOnlineCredentials”类型。例如。,

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#parameters
$SiteURL = "https://Crescent.sharepoint.com"
$UserName = "[email protected]"
$Password = "Password goes here"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force
  
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
$Ctx.Credentials = $Cred
  
#Get the Site Collection storage used
$Site = $Ctx.Site
$Ctx.Load($Site)
$Site.Retrieve("Usage")
$ctx.ExecuteQuery()
 
$StorageUsed = [Math]::Round(($Site.Usage.Storage/1MB),2)
 
#Get Site Collection Size
Write-host "Storage Used: $StorageUsed MB"
  1. 如果您尝试连接到租户管理站点,请确保租户管理 URL 为:https://YourDomain-admin.sharepoint.com,以下脚本会给您一个错误:Get-PnPSite:远程服务器返回错误:(403)禁止。

$TenantAdminURL = "https://crescent-admin.sharepoint.com/sites/london"
 
#Connect to the Site
Connect-PnPOnline -URL $TenantAdminURL -Interactive
 
Get-PnPSite

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯