In a previous post I've added content to the publishing pages in the legal and finance divisions and its useful to know what fields are in a list when working with the SharePoint API or say the Query By Content WebPart . Yes you can do using the UI but its a pain.
First get the SPWeb object for our site
$site=spweb "http://sps:2828/divisions/finance"
$web=$site.Openweb()
now show the lists on the site
$web.lists | select title,contenttypes
Title ContentTypes
----- ------------
Documents {Document, Folder}
Images {Document, Folder}
Master Page Gallery {Master Page, Folder}
Pages {Page, Article Page, Welcome Page, F...
Workflow History {Workflow History}
Workflow Tasks {Task, Folder}
The Pages list holds the publising pages so let's list its fields
$web.lists["Pages"].Fields | select title, internalname, typedisplayname | sort title
Title InternalName TypeDisplayName
----- ------------ ---------------
Approval Approval Workflow Status
Approval Status _ModerationStatus Moderation Status
Approver Comments _ModerationComments Multiple lines of text
Article Date ArticleStartDate Date and Time
Byline ArticleByLine Single line of text
Check In Comment _CheckinComment Lookup
Checked Out To CheckedOutTitle Lookup
Checked Out To CheckoutUser Person or Group
Checked Out To LinkCheckedOutTitle Computed
Client Limit Client_x0020_Limit Number
Collect Feedback CollectF Workflow Status
Collect Signatures CollectS Workflow Status
Contact PublishingContact Person or Group
Contact E-Mail Address PublishingContactEmail Single line of text
Contact Name PublishingContactName Single line of text
Contact Picture PublishingContactPicture Hyperlink or Picture
Content Type ContentType Choice
Content Type ID ContentTypeId Content Type Id
etc...
There are a lot of fields, to get the count use $web.lists["Pages"].Fields | measure-object
That gives 92 fields for the Pages library.
To see the content publishing pages themselves use
$web.lists["Pages"].Items | select name, file, level
Name File Level
---- ---- -----
default.aspx Pages/default.aspx Draft
Client1.aspx Pages/Client1.aspx Published
and finally two functions for our toolbox to make calling these easier
function get-SPListFields([string]$URL, [string]$ListName)
{
$site=get-spweb $URL
$web=$site.OpenWeb()
$list=$web.Lists[$ListName]
$list.Fields
}
function get-SPListItems([string]$URL, [string]$ListName)
{
$site=get-spweb $URL
$web=$site.OpenWeb()
$list=$web.Lists[$ListName]
$list.Items
}
These functions will come in useful later when we approve pages in a site with PowerShell.