我正在尝试在所有网站中获取网站集中所有网页的列表。 电源外壳不会返回任何东西。 这是我的power shell代码。请任何指导。
#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$str = "http://example.com/"
function ProcessSubWebs($str)
{
if([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($currentWeb))
{
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($currentWeb)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
{
if($publishingPage.ListItem['Title'] -ne $null)
{
select Uri, Title, @{Name=’PageLayout’;Expression={$_.Layout.ServerRelativeUrl}}
}
}
foreach($sub in $currentWeb.Webs)
{
if($sub.Webs.Count -gt 0)
{
ProcessSubWebs($sub)
}
}
Write-Host -ForegroundColor red "FINISHED"
}
else
{
Write-Host -Foregroundcolor Red "^ not a publishing site"
}
}
答案 0 :(得分:4)
我做了一些更改,包括调用函数。请将我的代码与您的代码进行比较,如果您有任何疑问,请与我们联系。这适用于我的环境。
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Set-location $home
$str = "http://example.com/"
function ProcessSubWebs($str)
{
$currentWeb = Get-SPWeb $str
if([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($currentWeb))
{
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($currentWeb)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
{
if($publishingPage.ListItem['Title'] -ne $null)
{
select Uri, Title, @{Name=’PageLayout’;Expression={$_.Layout.ServerRelativeUrl}}
$publishingPage | select Uri, Title, @{Name=’PageLayout’;Expression={$_.Layout.ServerRelativeUrl}}
}
}
foreach($sub in $currentWeb.Webs)
{
if($sub.Webs.Count -gt 0)
{
ProcessSubWebs($sub.Url)
}
}
Write-Host -ForegroundColor red "FINISHED"
}
else
{
Write-Host -Foregroundcolor Red "$str not a publishing site"
}
}
ProcessSubWebs($str)