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

[玩转系统] 如何使用 PowerShell 获取 SharePoint 中的内容类型 ID?

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

如何使用 PowerShell 获取 SharePoint 中的内容类型 ID?


要求:
内容类型的典型用途是 SharePoint 中的可重用元数据。有时,您可能需要按名称获取内容类型 ID,以便以编程方式将内容类型分配给列表和库。让我们使用 PowerShell 获取 SharePoint 2016 中的内容类型 ID。

如何在 SharePoint 列表中查找内容类型 ID?

要从 SharePoint 界面获取内容类型 ID:

  1. 在浏览器中打开 SharePoint 列表 >> 从功能区的“列表”选项卡中单击“列表设置”。
  2. 在“列表设置”页面中,单击“内容类型”下的目标内容类型 - 假设内容类型已启用。
  3. 现在,您将在 URL 中看到内容类型的 ID。最后一部分是内容类型 ID。例如,https://intranet.crescent.com/_layouts/15/ManageContentType.aspx?List=%7BEE1EA017%2DD347%2D49E6%2D9FE2%2D2CA7D1CB7B57%7D&ctype=0x01160074E6A09BFE52244F8ECB851FF 74077FC

    [玩转系统] 如何使用 PowerShell 获取 SharePoint 中的内容类型 ID?

相同的过程也适用于网站内容类型。转到网站设置 >> 网站内容类型 >> 选择您的内容类型 >> URL 将包含“Ctype”参数以及相应内容类型的内容类型 ID。

SharePoint 2016 PowerShell 获取内容类型 ID:

下面是从列表中按 ID 查找内容类型的 SharePoint PowerShell。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config Parameters
$WebURL="https://intranet.crescent.com"
$ListName="Projects"
$ContentTypeName="Contact Project"

#Get the Web, List and Content Type objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists.TryGetList($ListName)
#Get the content Type from its name
$ContentType = $List.ContentTypes | Where {$_.Name -Match $ContentTypeName}

#sharepoint get content type id by name
Write-Host $ContentType.ID 

同样,要使用 PowerShell 获取 SharePoint 中的网站内容类型 ID,请使用:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config Parameters
$WebURL="https://intranet.crescent.com"
$ContentTypeName="Crescent Configuration Entry"

#Get the Web, List and Content Type objects
$Web = Get-SPWeb $WebURL
#Get the content Type from its name
$ContentType = $Web.ContentTypes | Where {$_.Name -Match $ContentTypeName}

#sharepoint get content type id by name
Write-Host $ContentType.ID
如何通过ID获取内容类型?
$CT=$Web.ContentTypes |其中{$_.ID -eq“0x01005B3FBCA1E5314D57B4198D54F9F9B9CD”}

同样,要检索 SharePoint Online 中的内容类型 ID,请使用:如何使用 PowerShell 在 SharePoint Online 中获取内容类型 ID?

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

取消回复欢迎 发表评论:

关灯