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

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

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

SharePoint Online:如何使用 PowerShell 更改网站徽标?


要求:更改 SharePoint Online 网站中的徽标。

如何更改 SharePoint Online 中的徽标?

您想要更改 SharePoint Online 徽标吗?那么,在 SharePoint Online 网站品牌化方面,徽标更改是一项常见要求。也许您想更新公司的新徽标,使其与您的品牌更加一致。在本文中,我们将逐步引导您完成该过程。我们还将向您展示如何使用 PowerShell 更改 SharePoint Online 网站上的徽标。

如何向我的 SharePoint Online 网站添加徽标?要在 SharePoint Online 中设置徽标,请按照下列步骤操作:

  1. 以站点管理员身份登录到您的 SharePoint Online 站点。单击“设置”齿轮 >> 选择“站点设置”>> 在“站点设置”页面中,单击“标题、说明和徽标”链接 (/_layouts/15/prjsetng.aspx)。

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

  2. 这将带您进入一个页面,您可以在其中为站点设置徽标。您可以使用计算机中的徽标或 SharePoint 网站中的任何现有徽标(甚至还可以使用 Internet 上的任何现有图像)。
  3. 单击“从计算机”链接 >> 浏览并上传您的徽标文件。上传后,徽标文件将保存到网站的“网站资产”文档库中。

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

一旦您上传徽标图像,您就会发现新徽标立即反映在网站的左上角。或者,您可以输入徽标描述,该描述将成为新徽标的工具提示。单击“确定”按钮保存更改。单击“取消”放弃。

就是这样!您的新徽标现在将在您的经典体验 SharePoint Online 网站上可见。

SharePoint Online 默认徽标大小: 默认徽标大小为 64 像素 X 64 像素。 SharePoint 会自动缩小您的较大图像以适应 64 高 X 192 像素宽!

SharePoint Online:如何更改现代网站中的徽标

与经典版本的 SharePoint 网站不同,更改现代团队网站和通信网站的网站徽标确实非常简单,只需单击几下即可完成。

  1. 以网站所有者身份导航到现代 SharePoint 网站 >> 单击“设置”齿轮图标 >> 从网站设置菜单中单击“更改外观”。

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

  2. 在更改外观面板中,单击“标题”链接。

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

  3. 现在,您可以单击“站点徽标”下的“更改”按钮,浏览任何支持的徽标图像作为您站点的徽标。上传图像后,您将看到图像的预览。该标志将用在网站标题中。

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

  4. 单击“保存”应用您的更改。

您还可以更改带有方形徽标的站点徽标缩略图,以显示在搜索卡和站点卡中。如果您想恢复为默认的 SharePoint 徽标,请单击“删除”按钮。

SharePoint Online PowerShell 更改徽标:

从 Web UI 更改徽标非常简单,不是吗?那么,如果您有一个包含数百个子网站和子子网站的网站集怎么办?如果不同的网站使用您公司徽标的不同版本并希望使它们保持一致怎么办? PowerShell 就是答案!让我们使用 PowerShell 脚本更改 SharePoint Online 中的网站徽标。


#Add PowerShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking

##Configuration variables
$SiteUrl = "https://crescent.sharepoint.com/"
$LogoURL="/SiteAssets/Logo.png" #Existing file

Try {
    #Get 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
    $Web = $Ctx.Web

    #Change Logo
    $Web.SiteLogoUrl = $LogoURL
    $Web.Update()
    $Ctx.ExecuteQuery()

    Write-host "Logo Updated Successfully!" -ForegroundColor Green
}
Catch {
    write-host -f Red "Error updating Logo!" $_.Exception.Message
} 

请注意,LogoURL 中的文件 URL 必须是 SharePoint Online 网站上的现有文件。因此,首先将徽标上传到网站集的根目录。

用于更改网站集及其子网站的网站徽标的 PowerShell:

让我们更改 SharePoint Online 网站集中所有网站的徽标。在执行此脚本之前,请确保您已将“logo.png”文件上传到站点资源库中。


#Add PowerShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking

##Configuration variables
$SiteUrl = "https://crescent.sharepoint.com/Sites/Sales"
$LogoURL="/SiteAssets/Logo.png"

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

    #Function to change Logo for the given web
    Function Update-Logo($Web)
    {
        #Update Logo
        $Web.SiteLogoUrl = $LogoURL
        $Web.Update()
        $Ctx.ExecuteQuery()
        Write-host "Updated Logo for Web:" $Web.URL

        #Process each subsite in the site
        $Subsites = $Web.Webs
        $Ctx.Load($Subsites)
        $Ctx.ExecuteQuery()        
        Foreach ($SubSite in $Subsites)
        {
            #Call the function to change sharepoint site logo
            Update-Logo($Subsite)
        }
    }
    
    #Call the function to change the logo of the web
    Update-Logo($Web)
}
Catch {
    write-host -f Red "Error updating Logo!" $_.Exception.Message
}

PnP PowerShell 更改 SharePoint Online 网站集中所有网站的徽标

这次我们在网站集中的每个网站上设置徽标。我们不要引用顶级 Web 中的徽标,而是将其上传到每个网站,然后使用 PnP PowerShell 更改 SharePoint Online 中的网站徽标。


#Function to set site Logo
Function Set-PnPSiteLogo
{
[cmdletbinding()]
 
    param(
    [parameter(Mandatory = $true, ValueFromPipeline = $false)]$Web,
    [parameter(Mandatory = $true, ValueFromPipeline = $false)][String] $LogoFilePath
    )
   
    Try {
        Write-host "Updating Logo on Site '$($Web.URL)'"
        Connect-PnPOnline -Url $Web.URL -Interactive
 
        #Ensure "Site Assets" library in the site
        $SiteAssets = Get-PnPList -Identity "Site Assets" -ErrorAction SilentlyContinue 
        If($SiteAssets -eq $Null)
        {
            New-PnPList -Title "Site Assets" -Template DocumentLibrary -Url "SiteAssets" -ErrorAction SilentlyContinue | Out-Null
        }
 
        #Upload Logo File to 'Site Assets' library of the current web
        Add-PnPFile -Path $LogoFilePath -Folder "SiteAssets" | Out-Null
  
        #Get File Name from Logo File's Full Path
        $LogoFileName = Split-Path $LogoFilePath -leaf
 
        #Set Site Logo
        Set-PnpWeb -SiteLogoUrl "$($Web.ServerRelativeUrl)/SiteAssets/$($LogoFileName)"  
    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}
#Parameters
$SiteURL = "https://Crescent.sharepoint.com/sites/Marketing"
$LogoPath = "C:\Temp\Logo.jpg"
 
#Connect to Site
Connect-PnPOnline -Url $SiteURL -Interactive
$Webs = Get-PnPSubWeb -Recurse -IncludeRootWeb
 
#Call the function to change site logo
$Webs | ForEach-Object { Set-PnPSiteLogo -Web $_ -LogoFilePath $LogoPath }    

但是,此 PowerShell 仅适用于非群组连接的站点!

如何更改 Modern Group 连接网站上的徽标?

如果网站是在 Office 365 组或 Microsoft Teams 中创建的,则这些应用程序中更改的徽标不会反映回 SharePoint Online。只需替换“站点资产”库下的文件“__siteIcon__.jpg”(如果不存在,请创建一个!)即可更改站点徽标!

如果要使用 PowerShell 设置现代组连接站点的站点徽标,请使用带有“LogoFilePath”参数的 Set-PnPSite cmdlet:


$SiteURL = "https://crescent.sharepoint.com/sites/Purchase"
$LogoPath = "C:\Temp\Logo.jpg"

#Connect to Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Set Site Logo
Set-PnPSite -LogoFilePath $LogoPath

当尝试更改群组连接站点中的站点徽标时,我收到一条错误消息:“我们在更新图标时遇到问题。请在几分钟后再试一次。”这是因为: 尝试更改站点徽标的用户不是群组所有者!只需将用户添加为 Office 365 组所有者,他就应该能够更改网站徽标!

如何更改整个租户中所有网站和子网站的网站徽标?

此 PowerShell 脚本循环访问 Microsoft 365 租户中的每个 SharePoint 网站集,并根据参数更新徽标。该脚本可以处理经典站点和现代组连接站点。

在执行此脚本之前,请确保您已将自己作为网站集管理员添加到租户中的所有网站!如何将网站集管理员添加到租户中的所有 SharePoint Online 网站?

#Parameters
$Domain =  "Crescent" #Your Domain Name in SharePoint Online. E.g. https://Crescent.SharePoint.com
$LogoFilePath = "C:\Temp\SPLogo.jpg"
$Cred = Get-Credential

#Frame Tenant URL and Tenant Admin URL
$TenantURL = "https://$Domain.SharePoint.com"
$TenantAdminURL = "https://$Domain-Admin.SharePoint.com"

#Function to set site Logo
Function Set-PnPSiteLogo
{
    [cmdletbinding()]

   param(
    [parameter(Mandatory = $true, ValueFromPipeline = $True)]$Web,
    [parameter(Mandatory = $true, ValueFromPipeline = $False)][String] $LogoFilePath
    )
  
    Try {
        Connect-PnPOnline -Url $Web.URL -Credentials $Cred
        #Ensure "Site Assets" library in the site
        $SiteAssets = Get-PnPList -Identity "Site Assets" -ErrorAction SilentlyContinue 
        If($SiteAssets -eq $Null)
        {
            New-PnPList -Title "Site Assets" -Template DocumentLibrary -Url "SiteAssets" -ErrorAction SilentlyContinue | Out-Null
        }

        #Upload Logo File to 'Site Assets' library of the current web
        Add-PnPFile -Path $LogoFilePath -Folder "SiteAssets" | Out-Null
 
        #Get File Name from Logo File's Full Path
        $LogoFileName = Split-Path $LogoFilePath -leaf

        #Set Site Logo
        Set-PnpWeb -SiteLogoUrl "$($Web.ServerRelativeUrl)/SiteAssets/$($LogoFileName)"
        Write-host "`n`tUpdated Logo on Web '$($Web.URL)'" -f Green

    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}

#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred
    
#Get All Site collections - Exclude BOT, Video Portals and MySites
$Sites = Get-PnPTenantSite -Filter "Url -like $TenantURL -and Url -notlike '-my.sharepoint.com/' -and Url -notlike '/portals/'"
   
#Iterate through all site collections
$Sites | ForEach-Object {
    #Connect to each site collection
    Connect-PnPOnline -Url $_.URL -Credentials $Cred
    
    Write-host "Processing Site Collection:"$_.URL -f Yellow -NoNewline
    #Check if its a Group site
    If($_.Template -like 'GROUP*')
    {
        Set-PnPSite -LogoFilePath $LogoFilePath
        Write-host "`n`tUpdated Logo on Group Site!" -f Green
    }
    Else
    {   
        #Call the Function for site & all Subwebs
        Get-PnPSubWeb -Recurse -IncludeRootWeb | ForEach-Object { Set-PnPSiteLogo -Web $_ -LogoFilePath $LogoFilePath }
    }
}

如何更改现代 SharePoint Online 网站中的页眉布局、网站徽标和背景?在这里:如何使用 PowerShell 更改 SharePoint Online 中的标题布局、网站徽标、背景?

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

取消回复欢迎 发表评论:

关灯