PowerShell: get all fields / columns of a content type
this script both prints and write to a file
$site = Get-SPSite http://lamasadmin
$web = $site.RootWeb
$s = ""
foreach ($ctype in $web.ContentTypes)
{
if ($ctype.Id -eq "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2")
{
$ctype.Name + " " + $ctype.Id
foreach ($field in $ctype.Fields)
{
$field.Title + " " + $field.Id
$s += '"' + $field.Title + '", ' + $field.Id + [Environment]::NewLine
}
}
}
$s >> "c:\test.csv"
and to write is as html
$s += '<tr><td>' + $field.Title + '</td><td>' + $field.Id + '</td></tr>'
$site = Get-SPSite http://lamasadmin
$web = $site.RootWeb
$s = ""
foreach ($ctype in $web.ContentTypes)
{
if ($ctype.Id -eq "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2")
{
$ctype.Name + " " + $ctype.Id
foreach ($field in $ctype.Fields)
{
$field.Title + " " + $field.Id
$s += '"' + $field.Title + '", ' + $field.Id + [Environment]::NewLine
}
}
}
$s >> "c:\test.csv"
and to write is as html
$s += '<tr><td>' + $field.Title + '</td><td>' + $field.Id + '</td></tr>'
Comments
Post a Comment