网站搜索

在 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

相关文章