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

[玩转系统] SharePoint Online:使用 PowerShell 获取网站集 ID(或 Web ID)

作者:精品下载站 日期:2024-12-14 14:58:40 浏览:16 分类:玩电脑

SharePoint Online:使用 PowerShell 获取网站集 ID(或 Web ID)


要求:使用 PowerShell 获取 SharePoint Online 网站集或子网站的 ID。

如何获取 SharePoint Online 网站 ID?

如果您是 SharePoint 管理员,那么您有时很可能需要 SharePoint Online 网站集或子网站的 ID 来解决网站问题或将其提供给第三方开发人员。网站 ID 很容易找到,在这篇博文中,我们将向您展示如何获取 SharePoint Online 网站的网站 ID。

以下是如何查找具有 REST 端点的 SharePoint Online 网站集或子网站的 ID:

  1. 要获取网站集 ID,请在浏览器中点击以下 URL:https://.sharepoint.com/sites//_api/site/id
  2. 要获取子网站 ID(或 Web ID),请使用:https://.sharepoint.com//_api/web/id

    [玩转系统] SharePoint Online:使用 PowerShell 获取网站集 ID(或 Web ID)

这将为您提供站点的 ID,即 GUID。获取站点 ID 的另一种方法是使用 PowerShell 脚本!

SharePoint Online:用于获取网站集 ID 的 PowerShell

在 SharePoint Online 中,站点 ID 由系统自动生成,通常不需要用户关心。但是,有时您可能需要查找特定站点的站点 ID。要获取 SharePoint Online 中的网站集 GUID,请使用以下 PowerShell:


#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"

#Parameter
$SiteURL = "https://Crescent.sharepoint.com/Sites/Marketing"

#Get Credentials to connect
$Cred= Get-Credential
 
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Get Site and Web Objects
$Ctx.Load($Ctx.Site)
$Ctx.Load($Ctx.Web)
$Ctx.ExecuteQuery()

#sharepoint online powershell get site collection id
Write-host -f Green "Site ID:"$Ctx.Site.Id

#sharepoint online powershell get site id
Write-host -f Green "Web ID:"$Ctx.Web.Id

这将检索指定站点的 ID。您还可以使用此技术查找 SharePoint Online 中其他对象的 ID,例如列表和库。

用于获取站点和 Web ID 的 PnP PowerShell:

我们还可以使用 PnP PowerShell 检索网站集的 ID,如下所示:


#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Marketing"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the site collection with ID property
$Site = Get-PnPSite -Includes ID

#Get Site Collection ID
Write-host -f Green "Site Collection ID:"$Site.Id 

同样,要使用 PnP PowerShell 检索 SharePoint Online 中的子网站 ID,请使用:


#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Marketing/US"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Subsite with ID property
$Web = Get-PnPWeb -Includes ID

#Get Site ID
Write-host -f Green "Site ID:"$Web.Id

要获取 SharePoint Online 网站的租户 ID,请使用:如何获取 SharePoint Online 中的租户 ID?

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

取消回复欢迎 发表评论:

关灯