Búsqueda de sitios web

SharePoint Online: actualice los enlaces de inicio rápido mediante PowerShell


Requisito: Actualizar Inicio rápido en SharePoint Online mediante PowerShell.

¿Cómo actualizar enlaces de inicio rápido en SharePoint Online?

El inicio rápido ha sido una forma popular de organizar y acceder rápidamente al contenido del sitio en todas las versiones de SharePoint. Pero, ¿qué sucede si desea actualizar un enlace a una página o archivo en particular en su sitio por uno nuevo? Bueno, esto se puede lograr usando PowerShell y es relativamente fácil de hacer. Esta publicación de blog le mostrará cómo actualizar los enlaces en la barra de herramientas de Inicio rápido usando PowerShell.

Para actualizar enlaces en el inicio rápido, siga estos pasos:

  1. Vaya a Configuración del sitio >> Haga clic en "Inicio rápido" en Apariencia.
  2. Haga clic en el icono "Editar" para editar y actualizar el enlace de inicio rápido.

Si la función de publicación está habilitada, obtendrá el enlace "Navegación" en la configuración del sitio en "Apariencia"

SharePoint Online PowerShell para actualizar el inicio rápido:

Si necesita actualizar los vínculos en el Inicio rápido para varios sitios de SharePoint Online, hacerlo manualmente puede ser una tarea tediosa y que requiere mucho tiempo. Afortunadamente, se puede utilizar PowerShell para automatizar este proceso y ahorrar tiempo. Analicemos la actualización de los enlaces de inicio rápido en SharePoint Online mediante PowerShell.

Reemplacemos un enlace antiguo en la navegación izquierda con un enlace nuevo:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Config Parameters
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"
$OldURL = "https://support.crescent.com/app"
$NewURL = "https://support.crescent.com/applications"

#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 Quick launch Navigation of the web 
$QuickLaunch = $Ctx.Web.Navigation.QuickLaunch
$Ctx.load($QuickLaunch)
$Ctx.ExecuteQuery()

#Loop through Each link in Quick Launch Navigation
ForEach($QuickLaunchLink in $QuickLaunch)
{
    $Ctx.Load($QuickLaunchLink)
    $Ctx.Load($QuickLaunchLink.Children)
    $Ctx.ExecuteQuery()

    If($QuickLaunchLink.Url -eq $OldURL)
    {
        $QuickLaunchLink.Url = $QuickLaunchLink.Url.Replace($OldURL,$NewURL)
        $QuickLaunchLink.Update()
        $Ctx.ExecuteQuery()
        Write-Host -f Green "Quick Launch Link: '$($QuickLaunchLink.Title)' Updated!"
    }

    #Get Second level Links
    Foreach($Link in $QuickLaunchLink.Children)
    {
        $Ctx.Load($Link)
        $Ctx.ExecuteQuery()
          
        If($Link.Url -eq $OldURL)
        {
            $Link.Url = $Link.Url.Replace($OldURL,$NewURL)
            $Link.Update()
            $Ctx.ExecuteQuery()
            Write-Host  -f Green "Quick Launch Link '$($Link.Title)' Updated!"
        }
    }
} 

Actualizar enlace de inicio rápido para todas las colecciones de sitios

Incluyamos el script en una función y busquemos y reemplacemos enlaces de inicio rápido para todas las colecciones de sitios en el inquilino de SharePoint Online.


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Update-SPOQuickLaunchLinks([Microsoft.SharePoint.Client.Web]$Web, $OldURL, $NewURL)
{   
    Try {
        Write-host -f Yellow "Searching Quick Launch Links in:" $($Web.url)
        $Ctx = $Web.Context
        #Get the Quick launch Navigation of the web 
        $QuickLaunch = $Web.Navigation.QuickLaunch
        $Ctx.load($QuickLaunch)
        $Ctx.ExecuteQuery()

        #Loop through Each link in Quick Launch Navigation
        ForEach($QuickLaunchLink in $QuickLaunch)
        {
            $Ctx.Load($QuickLaunchLink)
            $Ctx.Load($QuickLaunchLink.Children)
            $Ctx.ExecuteQuery()

            If($QuickLaunchLink.Url -eq $OldURL)
            {
                $QuickLaunchLink.Url = $QuickLaunchLink.Url.Replace($OldURL,$NewURL)
                $QuickLaunchLink.Update()
                $Ctx.ExecuteQuery()
                Write-Host -f Green "`tQuick Launch Link: '$($QuickLaunchLink.Title)' Updated!"
            }

            #Get Second level Links
            Foreach($Link in $QuickLaunchLink.Children)
            {
                $Ctx.Load($Link)
                $Ctx.ExecuteQuery()
          
                If($Link.Url -eq $OldURL)
                {
                    $Link.Url = $Link.Url.Replace($OldURL,$NewURL)
                    $Link.Update()
                    $Ctx.ExecuteQuery()
                    Write-Host  -f Green "`tQuick Launch Link '$($Link.Title)' Updated!"
                }
            }
        }
    }
    Catch {
        write-host -f Red "Error Updating Quick Launch Links!" $_.Exception.Message
    }
}

#Function to get each subsite in site collection
Function Get-SPOWebs($SiteURL)
{
    $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 web
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.Load($Web.Webs)
    $Ctx.ExecuteQuery()

    #Call the function to Search & Replace Quick launch links
    Update-SPOQuickLaunchLinks -Web $web -OldURL $OldURL -NewURL $NewURL

    #Loop through each each subsite in site
    Foreach($Web in $web.Webs)
    {
        Get-SPOWebs $Web.Url
    }
}

#Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$OldURL = "https://support.crescent.com/app"
$NewURL = "https://support.crescent.com/applications"

#Setup Credentials to connect
$Cred= Get-Credential
 
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential ($Cred)

#Get all Site collections
$Sites = Get-SPOSite -Limit All

#Loop through site collections
ForEach($Site in $Sites)
{
    #Call the function to get all sites in the site collection
    Get-SPOWebs($Site.URL)
}

El mismo script también se puede utilizar para actualizar los enlaces de navegación principales. Simplemente reemplace $Web.Navigation.QuickLaunch con “$Web.Navigation.TopNavigationBar”

PnP PowerShell para actualizar enlaces de inicio rápido

De manera similar, también podemos actualizar el enlace de inicio rápido en SharePoint Online usando PnP PowerShell.


#Config Variables
$SiteURL = "https://crescent.sharepoint.com"
$LinkTitle = "Support Center"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the Context
$Context =  Get-PnPContext

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

#Get the Link to Update
$NavigationNode = $NavigationNodeCollection | Where-Object { $_.Title -eq  $LinkTitle}
If($NavigationNode)
{
    #Update the Link URL
    $NavigationNode.Url = "https://support.crescent.com"
    $navigationNode.Update() 
    $Context.ExecuteQuery()
    Write-host "Navigation Link has been updated!"
}

Al utilizar el script que se proporciona en este artículo, puede actualizar los enlaces de inicio rápido en sus sitios de SharePoint Online de forma rápida y eficiente.

Artículos relacionados