簡體   English   中英

使用 PowerShell 腳本和 CSOM 在 SharePoint Online 中設置網站徽標

[英]Set Site logo in SharePoint Online using PowerShell Script and CSOM

有沒有人能夠使用 Powershell 和 CSOM 在 SharePoint Online 網站上設置網站徽標? 謝謝

奈傑爾

以下代碼解決設置Site Logo(ctx為ClientContext):

ctx.Web.SiteLogoUrl = "/teams/test/SiteAssets/45.jpg";

ctx.Web.Update();

ctx.ExecuteQuery();

根據 UserVoice 請求使 SiteLogoUrl 屬性在 CSOM 中可用並發布UserVoice 推動對 SharePoint API改進,版本的SharePoint Online 客戶端組件 SDK Web類支持SiteLogoUrl屬性。

如何在 PowerShell 中使用 CSOM 設置Web.SiteLogoUrl property

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

Function Get-SPOCredentials([string]$UserName,[string]$Password)
{
   $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
   return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}

Function Web-SetLogo([Microsoft.SharePoint.Client.ClientContext]$Content,[string]$SiteLogoUrl)
{
   $Context.Web.SiteLogoUrl = $SiteLogoUrl
   $Context.Web.Update()
   $Context.ExecuteQuery()
}

$UserName = "username@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://contoso.sharepoint.com/"

$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password

Web-SetLogo -Content $context -SiteLogoUrl "/SiteAssets/ContosoLogo.jpg"

$context.Dispose()

這是在 sharepoint 2016 中使用 powershell 更改默認 sharepoint 徽標的腳本

$logoLocation= "http://sharepoint2016/SiteAssets/MyCompanyLogo.png"
$oSite=new-object Microsoft.SharePoint.SPSite("http://sharepoint2016/")
foreach($oWeb in $oSite.Allwebs) {
$oWeb.SiteLogoUrl=$logoLocation
$oWeb.Update()
}

此腳本可讓您一鍵更改完整網站集的徽標:

來源: https : //github.com/t1llo/change_logo_SharePointOnline-PS

重要提示:僅在 sharePoint Online Management Shell 中執行時才有效。

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

    ##Configuration variables
    $SiteUrl = "https://yoursite.collection.com/"
    $LogoURL="https://yourlogo.com"

    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 Recursively
                Update-Logo($Subsite)
            }
        }

        #Call the function to change logo of the web
        Update-Logo($Web)
    }
    Catch {
        write-host -f Red "Error updating Logo!" $_.Exception.Message
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM