2/28/2012

The SharePoint Site Icon and PowerShell

 

Governance and the desire for a consistent user interface may require you to occasionally change or reset the image used for the site icon.

 

First a few notes on the site icon

  • Sometimes Microsoft calls it the Site Icon and sometimes the Site Logo
     
  • The site logo is changed using Site Actions, Site Settings, Title, Description and Icon
        image
     
  • If the URL is blank in the top level site, then the default icon is used 
        image   (this icon is found here: /_layouts/images/siteIcon.png)
     
  • If the URL is blank in a sub site, the the icon from the top level site is used (not the icon from the next parent up)

Example:

  Top level site URL is blank, so the default icon is used (siteIcon.png)
  Subsite 1’s URL is supplied and has a custom icon
  Subsite 1A’s URL is blank, and the site display’s the top level site’s icon (siteIcon.png)

Then the icon for the top level site is changed to “newIcon.png”":

  The top level site displays the newIcon.png image
  Subsite 1’s URL is supplied and has a custom icon, and is unchanged after the change to the top level site
  Subsite 1A’s URL is blank, and now display’s the top level site’s new icon (newIcon.png)

 

Using PowerShell to document icon usage 

PowerShell can be used by administrators who have access to the SharePoint web servers to search and update SharePoint. The following scripts use the SharePoint 2010 cmdlets. Similar scripts could be written for SharePoint 2007 if needed.

 

The following PowerShell will list all of the sites in a site collection and their icons:

$site = Get-SPSite http://urlToYourSite
$site.AllWebs | foreach { $_.Url + "   Logo URL: " +  $_.SiteLogoUrl }

The result might look like this for the first example above:

http://intranet   Logo URL:
http://intranet/subsite1   Logo URL: /SiteAssets/CustomLogo.jpg
http://intranet/subsite1/subsite1a   Logo URL:

 

And after changing the top level’s icon to “newIcon.png” might look like this:

http://intranet   Logo URL: /SiteAssets/NewIcon.png
http://intranet/subsite1   Logo URL: /SiteAssets/CustomLogo.jpg
http://intranet/subsite1/subsite1a   Logo URL: /SiteAssets/NewIcon.png

If you want to dump all sites in a web application you could use this PowerShell:  (all one line)

Get-SPWebApplication "http://intranet" | Get-SPSite "| Get-SPWeb | 
foreach { $_.Url + "
Logo URL: " + $_.SiteLogoUrl }

Or for all webs in all site collections in all applications:

Get-SPWebApplication | Get-SPSite | Get-SPWeb | 
foreach { $_.Url + " Logo URL: " + $_.SiteLogoUrl }

 

Changing the Site Icon

This following PowerShell script sets the icon in every subsite of a site collection to an icon stored in the Site Assets library of the top level site. 
  NOTE 1: This will change the top level site and EVERY subsite in the site collection. 
  NOTE 2: There is no undo.
  NOTE 3: The users of all of the subsites will need at least Read permissions to the icon file.

$site = Get-SPSite http://urlToYourSiteCollection
$site.AllWebs | foreach { $_.SiteLogoUrl = "/SiteAssets/NewLogo.jpg"; $_.Update() }

If you set the SiteLogoUrl to "" then all the sites revert to the default site logo.

$site = Get-SPSite http://urlToYourSiteCollections
$site.AllWebs | foreach { $_.SiteLogoUrl = ""; $_.Update() }

If you wanted to set the URL so each site would point to its own custom image in its own library then you can add “../../” to the URL:  (the following is all one line)

 $site.AllWebs | foreach { $_.SiteLogoUrl = "../../SiteAssets/NewLogo.jpg"; 
$_.Update() }

 

.

4 comments:

Keith Oswalt said...

Perfect! Thank you for your post.

Joe F said...

Thank you for this. Greatly appreciate.

Anders Faxedahl said...

Thank You, worked like a charm...

Dude said...

Excellent post, script does what it should do.
Thanks for sharing.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.