当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 更改导航设置

作者:精品下载站 日期:2024-12-14 14:36:43 浏览:16 分类:玩电脑

SharePoint Online:使用 PowerShell 更改导航设置


要求: SharePoint Online 使用 PowerShell 设置导航。

如何更改 SharePoint Online 中的导航?

SharePoint Online 能够自定义导航,使用户更轻松地查找和访问内容。在这篇博文中,我们将向您展示如何更改 SharePoint Online 中的导航。我们还将向您展示如何使用 PowerShell 设置网站的导航选项。

要更改 SharePoint Online 中的导航,请转到:

  • 站点设置>>“外观和感觉”组下的“导航”
  • 相应地设置全局导航和当前导航的导航设置。

[玩转系统] SharePoint Online:使用 PowerShell 更改导航设置

SharePoint Online:使用 PowerShell 设置导航

以下是设置 SharePoint Online 导航的 PowerShell:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Publishing.dll"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing/2018"

#Get Credentials to connect
$Cred = Get-Credential
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
   
    #Get the Web
    $Web = $Ctx.Web
    $ctx.Load($Web)
    $Ctx.ExecuteQuery()

    $TaxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
    $NavigationSettings = New-Object Microsoft.SharePoint.Client.Publishing.Navigation.WebNavigationSettings($Ctx, $Web)

    #Set Both current and global navigation settings to structural - Other values: PortalProvider,InheritFromParentWeb ,TaxonomyProvider
    $NavigationSettings.GlobalNavigation.Source = "PortalProvider"
    $NavigationSettings.CurrentNavigation.Source = "PortalProvider"

    #Show subsites in Global navigation
    $Web.AllProperties["__IncludeSubSitesInNavigation"] = $True

    #Show pages in global navigation
    $Web.AllProperties["__IncludePagesInNavigation"] = $False

    #Maximum number of dynamic items to in global navigation
    $web.AllProperties["__GlobalDynamicChildLimit"] = 15

    #Update Settings
    $Web.Update()
    $NavigationSettings.Update($TaxonomySession)
    $Ctx.ExecuteQuery()

    Write-host -f Green "Navigation Settings Updated!"
}
Catch {
    write-host -f Red "Error Updating Navigation Settings!" $_.Exception.Message
}

包起来

在本文中,我们讨论了如何使用 PowerShell 更改 SharePoint Online 中的导航设置。通过本指南中概述的步骤,您可以轻松快速地更改网站的导航设置。您可以使用 PowerShell 自动执行此过程,并使您的 SharePoint Online 环境更易于管理和维护。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯