【发布时间】:2012-03-16 02:45:15
【问题描述】:
我正在尝试编写一个 powershell 脚本,该脚本将在我的 sharepoint 2010/2007 页面上运行,并将列出其页面布局并将结果保存到文本文件中。
在运行我写的以下脚本时,我在几分钟后得到一个错误:
EnumeratePages : 调用的目标已抛出异常。 在 T:\listpages.ps1:75 char:15 + 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
请指教。
【问题讨论】:
-
您是否尝试过使用 ISE 或 PowerGUI 进行调试?
-
尝试调试它。但是你说“几分钟后”——运行脚本的几分钟?超时?
-
运行脚本几分钟后。不超时
-
@חגאי 我认为您的某些页面存在问题。要查找有问题的页面 url,请在此处添加 try-catch:powershell 2.0 try catch how to access the exception
标签: sharepoint powershell sharepoint-2010 sharepoint-2007