使用power shell获取具有页面布局的SharePoint页面列表

使用power shell获取具有页面布局的SharePoint页面列表,shell,powershell,sharepoint,sharepoint-2010,sharepoint-2013,Shell,Powershell,Sharepoint,Sharepoint 2010,Sharepoint 2013,我正在尝试获取我的网站集合中所有网页的列表。 电源外壳不返回任何东西。 这是我的powershell代码。有什么指导吗 #Add SharePoint PowerShell SnapIn if not already added if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoi

我正在尝试获取我的网站集合中所有网页的列表。 电源外壳不返回任何东西。 这是我的powershell代码。有什么指导吗

#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)

我做了一些更改,包括调用函数。请将我的代码与您的代码进行比较,如果您有任何问题,请告诉我。这在我的环境中起作用

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)

谢谢,行得通我把输出格式改成了表格谢谢,行得通我把输出格式改成了表格