使用PowerShell脚本和CSOM在SharePoint Online中设置站点徽标

时间:2014-07-07 11:48:56

标签: powershell sharepoint csom

是否有人能够使用Powershell和CSOM在SharePoint Online网站上设置网站徽标? 感谢

4 个答案:

答案 0 :(得分:1)

以下代码解决了设置Site Logo(ctx是ClientContext)的问题:

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

ctx.Web.Update();

ctx.ExecuteQuery();

答案 1 :(得分:1)

根据UserVoice请求Make the SiteLogoUrl property available in CSOM和帖子UserVoice driving improvements to SharePoint APISharePoint Online Client Components SDK Web类的版本支持SiteLogoUrl属性。< / p>

如何在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()

答案 2 :(得分:0)

这是使用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()
}

答案 3 :(得分:0)

此脚本可让您一键更改整个网站集的徽标:

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

重要提示:仅在sharePoint Online命令行管理程序中执行时有效。

#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
    }