我正在尝试获取所有网站中我的网站集中所有页面的列表。
电源壳不返回任何东西。
这是我的电源 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"
}
}
最佳答案
我进行了一些更改,包括调用函数。请将我的代码与您的代码进行比较,如果您有任何疑问,请告诉我。这在我的环境中有效。
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)
关于shell - 使用Power Shell获取具有页面布局的SharePoint页面列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25289146/