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

[玩转系统] SharePoint Online:如何使用 PowerShell 更改网站主题?

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

SharePoint Online:如何使用 PowerShell 更改网站主题?


在 SharePoint Online 中,您可以通过更改主题来自定义网站的外观和风格以反映您的公司品牌。 SharePoint Online 中的主题定义 SharePoint 网站的颜色、字体、图像和页面布局。 SharePoint 提供了一组默认的网站主题,我们还能够创建和部署自定义主题。

这篇文章将指导您完成更改网站主题所需的步骤。我们还将分享如何使用 PowerShell 更改 SharePoint Online 网站主题,以便您可以在网站上的不同主题之间快速切换,而无需浏览“网站设置”页面并手动进行更改。

如何更改经典 SharePoint Online 网站中的主题?

要更改站点的主题,请执行以下操作:

  1. 导航到要更改主题的 SharePoint Online 网站 >> 在网站主页上,单击“设置”齿轮 >> 从“网站设置”菜单中选择“更改外观”。

    [玩转系统] SharePoint Online:如何使用 PowerShell 更改网站主题?

  2. 在“更改外观”页面上,选择要用作新网站布局起点的主题。 (您还可以转到“站点设置”>>单击“外观和感觉”部分中的“更改外观”链接)

    [玩转系统] SharePoint Online:如何使用 PowerShell 更改网站主题?

  3. 在更改外观配置页面上,您可以进一步自定义主题以满足您的要求,例如:

    • 您可以更改背景图像(或将其删除)。
  4. 可以使用颜色下拉列表进一步更改主题的配色方案并选择所需的颜色组合。
  5. 网站母版页布局可以更改为两种可用的页面布局:奥斯陆和西雅图。
  6. 可以选择网站中使用的字体系列。从字体下拉列表中选择字体列表。
  7. 对主题的背景图像、颜色、站点布局和字体进行任何更改后,可以通过单击“试用”链接来测试主题。单击此链接将生成外观预览。您看到的布局与网站中显示的布局相同。

    [玩转系统] SharePoint Online:如何使用 PowerShell 更改网站主题?

  8. 在预览页面上,确定外观是否完整。单击“不,不完全在那里”链接将返回“更改外观”配置页面,您可以在其中自定义外观。单击“是,保留”链接会更改网站的当前主题。

    [玩转系统] SharePoint Online:如何使用 PowerShell 更改网站主题?

您可以通过切换到“Office”主题来重置 SharePoint Online 网站的主题!转到站点设置>>外观和感觉>>更改外观。 >> 选择“Office”主题并应用。这将为您提供默认的 Microsoft 外观。任何具有“设计”或“完全控制”权限级别的用户都可以更改网站主题!这是我关于在本地 SharePoint 中使用 PowerShell 更改主题的另一篇文章:如何在 SharePoint 中使用 PowerShell 应用主题?

主题生成器工具可在线获取:https://aka.ms/themedesigner

中心站点中的主题继承:

主题在与中心关联的所有站点之间继承!如果您尝试配置与中心关联的站点的外观和风格,您将收到“您的站点已连接到 中心站点并设置为自动采用相同主题”的通知。信息。因此,要更改关联站点的主题,您需要转到中心站点并在那里设置主题选项!

[玩转系统] SharePoint Online:如何使用 PowerShell 更改网站主题?

SharePoint Online:使用 PowerShell 应用主题

要以编程方式更改 SharePoint 主题,我们需要“组合外观”列表中模板的主题 Url、图像 Url 和字体方案 URL。您可以通过导航网站集的“/_catalogs/design/AllItems.aspx”URL 来获取它们。


#Import PowerShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
    
#Parameters for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/marketing"
$ColorPaletteUrl = "/sites/marketing/_catalogs/theme/15/palette002.spcolor"
$FontSchemeUrl =  "/sites/marketing/_catalogs/theme/15/fontscheme002.spfont"
$BackgroundImageUrl = "/_layouts/15/images/image_bg002.jpg"

#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()
    
    #Apply Theme
    $Web.ApplyTheme($ColorPaletteUrl,$FontSchemeUrl,$BackgroundImageUrl,$True)
    $Ctx.ExecuteQuery()
}
catch {
    write-host "Error Changing Theme: $($_.Exception.Message)" -foregroundcolor Red
}

如果要跳过字体方案或背景图像参数,请将这些变量设置为 Out-Null。例如。 $BackgroundImageUrl=Out-Null。

PowerShell 将主题应用到 SharePoint Online 中的子网站:

让我们更改 SharePoint Online 网站集中所有网站的主题。


#Import PoweShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Parameters for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/marketing"
#Theme URLs - Located only at Root Site
$ColorPaletteUrl = "/sites/marketing/_catalogs/theme/15/palette001.spcolor"
$FontSchemeUrl =  "/sites/marketing/_catalogs/theme/15/fontscheme001.spfont"
$BackgroundImageUrl = "_layouts/15/images/image_bg001.jpg"

#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 Root web
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.ExecuteQuery()

    #Function to change the site theme
    Function Set-SPOSiteTheme($Web)
    {
        #Apply Theme
        $Web.ApplyTheme($ColorPaletteUrl,$FontSchemeUrl,$BackgroundImageUrl,$True)
        $Ctx.ExecuteQuery()
        Write-host -f Green "Theme Applied on site '$($Web.Url)' Successfully!"

        #Process each subsite in the site
        $Subsites = $Web.Webs
        $Ctx.Load($Subsites)
        $Ctx.ExecuteQuery()        
        Foreach ($SubSite in $Subsites)
        {
            #Call the function Recursively
            Set-SPOSiteTheme($Subsite)
        }
    }
    #Call the function to change the theme of the web
    Set-SPOSiteTheme($Web)
}
catch {
    write-host "Error Changing Theme: $($_.Exception.Message)" -foregroundcolor Red
}

PnP PowerShell 在 SharePoint Online 中设置主题

可以使用 SharePoint Online 中的 Set-PnPTheme cmdlet 应用主题。


#Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"

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

#Change Set Theme
Set-PnPTheme -ColorPaletteUrl "/_catalogs/theme/15/palette008.spcolor" -BackgroundImageUrl "/_layouts/15/images/image_bg008.jpg" -FontSchemeUrl "/_catalogs/theme/15/fontscheme003.spfont"

使用 PnP PowerShell 从父站点继承主题
我们可以使用 -ResetSubwebsToInherit 开关继承主题并将其应用到子站点。具体方法如下:


Set-PnPTheme -ColorPaletteUrl "/_catalogs/theme/15/palette008.spcolor" -BackgroundImageUrl "/_layouts/15/images/image_bg008.jpg" -FontSchemeUrl "/_catalogs/theme/15/fontscheme003.spfont" -ResetSubwebsToInherit

这使得子网站继承主题!

从站点中删除主题(将站点主题重置为默认值):
您可以通过调用不带任何参数的 cmdlet“Set-PnPTheme”来重置主题,这会从站点中删除主题!

结论

总之,通过网站设置页面或 PowerShell 使用 Web 浏览器界面可以轻松更改 SharePoint Online 中的网站主题。 PowerShell 方式提供了一种方便且自动化的方式来管理 SharePoint 网站的外观,从而可以快速轻松地更改网站的外观。无论您想要更改配色方案、字体还是背景,使用 PowerShell 都可以让您快速轻松地进行这些更改,而无需手动更新站点的每个页面。这对于拥有多个站点的组织特别有帮助,因为该过程可以轻松实现自动化,从而节省时间和精力。通过使用 PowerShell 更改 SharePoint Online 中的网站主题,组织可以改善用户体验、增强其网站的品牌,并确保其内容以具有视觉吸引力和专业的方式呈现。

相关文章:

  • 要将新式主题应用到 SharePoint Online 网站,请使用:SharePoint Online:使用 PowerShell 应用新式主题
  • 若要在 SharePoint Online 中添加自定义主题,请使用:SharePoint Online:使用 PowerShell 添加自定义主题

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

取消回复欢迎 发表评论:

关灯