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

[玩转系统] 在 SharePoint 中使用 PowerShell 获取内容类型字段

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

在 SharePoint 中使用 PowerShell 获取内容类型字段


要求:PowerShell 获取 SharePoint 中的内容类型字段。

SharePoint PowerShell 获取内容类型字段

这是我的 PowerShell,用于获取内容类型及其列,循环遍历它们,并输出包含以下数据的 CSV 文件:

  • 栏目标题
  • 列内部名称
  • 列号
  • 列组
  • 栏目说明

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Variables for processing
$SiteURL = "https://intranet.crescent.com"
$ContentTypeName = "Credit Projects"
$OutputFile = "C:\Temp\ContentTypes.csv"

#Get the Web
$Web = Get-SPWeb $SiteURL

#Get the Content Type
$CType = $Web.ContentTypes[$ContentTypeName] 

$ResultArray = @()
#Loop through the Fields in the Content Type
ForEach ($Field in $CType.Fields)
{
    # Create a new custom object to hold our row of data with property names:
    $Result = New-Object PSObject
    $Result | Add-Member -MemberType NoteProperty -Name "Title" -Value $field.Title
    $Result | Add-Member -MemberType NoteProperty -Name "Internal Name" -Value $field.InternalName
    $Result | Add-Member -MemberType NoteProperty -Name "ID" -Value $field.Id
    $Result | Add-Member -MemberType NoteProperty -Name "Group" -Value $field.Group
    $Result | Add-Member -MemberType NoteProperty -Name "Description" -Value $field.Description

    #Add the object to array
    $ResultArray += $Result
}

# Export the results to CSV
$ResultArray | Export-Csv $OutputFile -NoTypeInformation

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

取消回复欢迎 发表评论:

关灯