shell - 使用Power Shell获取具有页面布局的SharePoint页面列表

标签 shell powershell sharepoint sharepoint-2010 sharepoint-2013

我正在尝试获取所有网站中我的网站集中所有页面的列表。
电源壳不返回任何东西。
这是我的电源 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/

相关文章:

linux - pidof -x $0 返回 2 而不是预期的 1,是否有单行替代方案?

linux - 防止文件被linux中的另一个进程移动

regex - 在PowerShell中替换字符串中的第一个匹配字符

SharePoint 2010,Powershell - 遍历所有文档库,创建 View 并将其设置为默认值

linux - 64 位 Linux 上的缓冲区溢出

linux - 在 shell 脚本中每秒运行一次 for 循环

excel - 在powershell中打开受密码保护的Excel

powershell - 在powershell中读取目录中所有文件的所有行的最简单方法

excel - 无法在 Excel Webaccess Webpart 中刷新 Excel 连接

Sharepoint 搜索错误 : The SharePoint server was moved to a different location, 自定义登录页面