深入浅出SharePoint——使用PowerShell导出站点的导航

 

 

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function ExportQuickLaunchNavigation(
    [Microsoft.SharePoint.SPWeb] $web)
{
    $xml = [xml] "<QuickLaunch/>"

    foreach ($navigationNode in $web.Navigation.QuickLaunch)
    {
        AddNavigationElement $navigationNode $xml.DocumentElement
    }

    return $xml
}

function AddNavigationElement(
    [Microsoft.SharePoint.Navigation.SPNavigationNode] $navigationNode,
    [System.Xml.XmlElement] $parentElement)
{
    $navElement = $parentElement.OwnerDocument.CreateElement("NavigationNode")

    $parentElement.AppendChild($navElement) > $null

    $navElement.SetAttribute("title", $navigationNode.Title)
    $navElement.SetAttribute("url", $navigationNode.Url)

    foreach ($childNode in $navigationNode.Children)
    {
        AddNavigationElement $childNode $navElement
    }
}

$webUrl="http://cris-moss/sites/Mockup/";
$null = [System.Reflection.Assembly]::LoadFrom("C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI\Microsoft.SharePoint.dll")
$site =  New-Object -TypeName "Microsoft.SharePoint.SPSite" -ArgumentList "$webUrl";
$web = $site.OpenWeb()

$navigationXml = ExportQuickLaunchNavigation($web)

$navigationXml.OuterXml

  

posted @ 2013-04-09 14:52  风影极光  阅读(361)  评论(0编辑  收藏  举报