我正在尝试编写一个PowerShell脚本,该脚本将在我的sharepoint 2010/2007页面上运行,并将列出其页面布局,并将结果保存到文本文件中。
在运行下面的脚本时,我得到了一些错误:
EnumeratePages:调用目标抛出了异常。 在T:\ listpages.ps1:75 char:15 + EnumeratePages<<<< ( 'http://preportal.idc.ac.il') + CategoryInfo:NotSpecified:(:) [EnumeratePages],TargetInvocationException + FullyQualifiedErrorId:System.Reflection.TargetInvocationException,EnumeratePages
# Add SharePoint cmdlets reference
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
function EnumeratePages($Url) {
$site = new-object Microsoft.SharePoint.SPSite $Url
foreach($web in $site.AllWebs) {
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) {
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pages = $pWeb.PagesList
Write-Host "Processing Web:" $pWeb.Url "..." -ForegroundColor Magenta
foreach ($item in $pages.Items) {
$fileUrl = $pWeb.Url + $webUrl + "/" + $item.File.Url
Write-Host " " $fileUrl -ForegroundColor Green
foreach ($fld in $item.Fields)
{
if($fld.Title -and $fld.InternalName -and $item[$fld.InternalName])
{
if($fld.InternalName -eq "PublishingPagelayout")
{
Write-Host "PublishingPagelayout: " + $item[$fld.InternalName].ToString()
Select "Page Url: ", $fileUrl, "PublishingPagelayout: ", $item[$fld.InternalName].ToString() | Format-List
}
}
#$spFile = $web.GetFile($fileUrl.ToString())
#if($spFile.Properties.Count -gt 0)
#{
#}
}
}
}
else {
Write-Host " Not a publishing web:" $web.Url". Looking for Site Pages library." -ForegroundColor Magenta
$pages = $null
$pages = $web.Lists["Site Pages"]
if ($pages) {
Write-Host " " $pages.Title "found." -ForegroundColor Green
foreach ($item in $pages.Items) {
$fileUrl = $pWeb.Url + $webUrl + "/" + $item.File.Url
Write-Host " " $fileUrl -ForegroundColor Green
foreach ($fld in $item.Fields)
{
if($fld.Title -and $fld.InternalName -and $item[$fld.InternalName])
{
if($fld.InternalName -eq "PublishingPagelayout")
{
Write-Host "PublishingPagelayout: " + $item[$fld.InternalName].ToString()
Select "Page Url: ", $fileUrl, "PublishingPagelayout: ", $item[$fld.InternalName].ToString() | Format-List
}
}
}
#$spFile = $web.GetFile($fileUrl)
#if($spFile.Properties.Count -gt 0)
#{
#}
}
else {
Write-Host " Site Pages library not found." -ForegroundColor Red
}
}
Write-Host "... completed processing" $web "..." -ForegroundColor Magenta
}
}
}
$row = EnumeratePages('http://server-name')
$row > t:\SitePagesPropertiesReport2.txt
请告知。
答案 0 :(得分:2)
这将用于发布页面:
filter Get-PublishingPages {
$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)
$query = new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$pubweb.GetPublishingPages($query)
}
get-spweb $url | Get-PublishingPages | select Uri, Title, @{Name='PageLayout';Expression={$_.Layout.ServerRelativeUrl}}