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

[玩转系统] SharePoint Online:使用 PowerShell 删除快速启动或顶部导航中的链接

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

SharePoint Online:使用 PowerShell 删除快速启动或顶部导航中的链接


要求:从 SharePoint Online 顶部导航或快速启动栏中删除节点。

如何从 SharePoint Online 顶部导航或快速启动栏中删除链接?

您是否想要删除 SharePoint Online 网站的快速启动或顶部导航中的链接?也许您不想再在导航中显示某个链接,或者您想对用户隐藏某个链接。本博文将向您展示如何使用 PowerShell 从 SharePoint Online 的快速启动或顶部导航中删除链接。

如何从 SharePoint Online 导航中删除链接?

要从 SharePoint Online 网站导航中删除链接,请按照下列步骤操作:

  1. 以网站所有者或管理员身份登录到您的 SharePoint Online 网站。
  2. 单击左侧导航栏或顶部导航栏末尾的“编辑”链接。

    [玩转系统] SharePoint Online:使用 PowerShell 删除快速启动或顶部导航中的链接

  3. 将鼠标悬停在导航中要删除的链接上>>单击小三个点>>从上下文菜单中选择“删除”。

    [玩转系统] SharePoint Online:使用 PowerShell 删除快速启动或顶部导航中的链接

  4. 单击“保存”保存更改。

现在应该从现代 SharePoint Online 网站的快速启动或顶部导航栏中删除该链接。

按照上述步骤操作,您可以轻松地从 SharePoint Online 的快速启动或顶部导航中删除链接,从而更好地控制网站的导航和组织。

当发布功能处于活动状态时从导航中删除链接

当发布功能处于活动状态时,情况会略有不同:

  1. 转到站点设置>>单击“外观”中的“导航”(如果未启用发布功能,您可能必须使用“顶部链接栏”!)
  2. 在全局导航(顶部导航)或当前导航(快速启动)中选择导航节点或链接
  3. 单击“删除”图标可从导航中删除链接。
  4. 单击页面底部的“确定”按钮保存更改。

[玩转系统] SharePoint Online:使用 PowerShell 删除快速启动或顶部导航中的链接

使用 PowerShell 删除 SharePoint Online 中的导航节点

以下是用于从 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"

#Remove Link from Navigation
Function Remove-SPONavigationNode()
{
    Param([Microsoft.SharePoint.Client.NavigationNodeCollection]$Navigation, [String]$NavigationTitle)

    #Iterate through and Remove the Node from Navigation
    For($i = $Navigation.Count - 1; $i -ge 0; $i--)
    {
        If($Navigation[$i].Title -eq $NavigationTitle)
        {
            $Navigation[$i].DeleteObject()
            $Ctx.ExecuteQuery()
            Write-Host -f Green "Removed " $NavigationTitle 
        }
        Else
        {
            #Check in 2nd Level Links
            $ChildLinks = $Navigation[$i].Children
            $Ctx.Load($ChildLinks)
            $Ctx.ExecuteQuery()

            #Call the function recursively
            If($ChildLinks.Count -gt 0)
            {
                Remove-SPONavigationNode -Navigation $ChildLinks -NavigationTitle $NavigationTitle
            }
        }
    }
}
 
#Config Parameters
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get the Top Navigation bar of the web
$TopNavigation = $Ctx.Web.Navigation.TopNavigationBar #For Quick Launch, use: $Ctx.Web.Navigation.QuickLaunch
$Ctx.load($TopNavigation)
$Ctx.ExecuteQuery()

#Call the function to Remove a Node from navigation
Remove-SPONavigationNode -Navigation $TopNavigation -NavigationTitle "Support Center"

此 PowerShell 删除给定的导航节点及其所有子节点!

PnP PowerShell 用于删除快速启动导航中的链接

让我们使用 PnP PowerShell cmdlet Remove-PnPNavigationNode 从 SharePoint Online 网站的左侧导航中删除指向“/_layouts/15/viewlsts.aspx”的“网站内容”链接。


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$LinkTitle = "Site contents"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get Quick Launch Navigation
$NavigationNodeCollection = Get-PnPNavigationNode -Location QuickLaunch

#Get the Link to Delete
$NavigationNode = $NavigationNodeCollection | Where-Object { $_.Title -eq  $LinkTitle}

#Delete Link from left navigation 
Remove-PnPNavigationNode -Identity $NavigationNode.Id -Force

使用 PnP PowerShell 从顶部导航中删除链接

这次,我们从 SharePoint Online 网站的顶部导航栏中删除“主页”链接。


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$LinkTitle = "Home"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Top Navigation Bar
$NavigationNodeCollection = Get-PnPNavigationNode -Location TopNavigationBar

#Get the Link to Delete
$NavigationNode = $NavigationNodeCollection | Where-Object { $_.Title -eq  $LinkTitle}

#Delete Link from Top navigation 
Remove-PnPNavigationNode -Identity $NavigationNode.Id -Force

要将新链接添加到左侧导航或顶部导航栏,请使用:如何使用 PowerShell 在 SharePoint Online 中添加快速启动导航链接?

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

取消回复欢迎 发表评论:

关灯