0

After migration from 2007>2010>2013 for all lists ImageUrl property is still on 2007. If someone have powershell script which updates all lists on site SPList.ImageUrl property from SP2007 version to SP2013 version that will be great :)

I have this right now on SP2013 for all lists.

SPList.ImageUrl property for SP2007

/_layouts/images/lttask.gif

enter image description here

And i need update ImageUrl for all web, sub web and lists on web app that i get this

SPList.ImageUrl property for SP2013

/_layouts/15/images/ittask.png?rev=23

enter image description here

This powershell is only for one list.

if ( (Get-PSSnapin -Name Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
    Write-Host "PSSnapin for SharePoint is now ON" -ForegroundColor Green `n
}
else{
Write-Host "PSSnapin for SharePoint already ON" -ForegroundColor Magenta `n
}
$web = Get-SPWeb http://SITE
$list = $web.Lists["Test"]
$list.ImageUrl = "/_layouts/15/images/itann.png?rev=23"
$list.Update()

I need powershell script for all lists on web app which will change /_layouts/images/ittask.gif into /_layouts/15/images/ittask.png?rev=23. Image names are different for lists (ittask,ltgen...)

Thank you ;)

2 Answers 2

1

Here you go:

$WebApp = Get-SPWebApplication "http://webappurl"
if ($WebApp -ne $null)
{
    foreach ($site in $WebApp.Sites) 
    {
       foreach ($web in $site.AllWebs) 
        {
            for ($i = 0; $i -lt $web.Lists.Count; $i++)
            {
                $list = $web.Lists[$i];

                if($list.Hidden -eq $false)
                {
                    if($list.BaseTemplate -eq "Announcements")
                    {
                        $list.ImageUrl = "/_layouts/15/images/itann.png?rev=23"
                        $list.Update()
                    } elseif ($list.BaseTemplate -eq "Events") {
                        #different icon
                    }
                    #etc
                }
            }
        }
    }
}
4
  • Thank you for this script. I was thinking to parse $list.ImageUrl /_layouts/images/itann.gif , change to/_layouts/15/images/itann.png?rev=23 and then $list.Update().
    – Marko Tica
    Oct 13, 2015 at 15:02
  • You could do that. You might as well check for different types of lists and assign a different icon. Oct 13, 2015 at 15:04
  • I need foreach list update url but there is many different types so i need to parse that so i get only "itann" for ex. And exclude hidden list. Thanks :)
    – Marko Tica
    Oct 13, 2015 at 15:08
  • Refer to my updated answer. The script checks for different types of lists and excludes hidden lists as well. Oct 13, 2015 at 15:15
1

Final script

For whole web application!

Script change list imageurl to 2013 style on whole web app for all site collections and webs.

if ( (Get-PSSnapin -Name Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
    Write-Host "[INIT] Loading SharePoint Powershell Snapin" -ForegroundColor Green
}
else{
    Write-Host "[INIT] SharePoint Powershell Snapin already loaded" -ForegroundColor Magenta
}
$WebApp = Get-SPWebApplication "http://YOURWEBAPPURL"
if ($WebApp -ne $null)
{
    foreach ($site in $WebApp.Sites) 
    {
       foreach ($web in $site.AllWebs) 
        {
            for ($i = 0; $i -lt $web.Lists.Count; $i++)
            {
                $list = $web.Lists[$i];

                if($list.Hidden -eq $false)
                {               
                    $ListURL = $list.ParentWeb.Url + ‘/’ + $list.RootFolder.Url             
                    Write-Host -ForegroundColor Green "List title: "$list.Title `n"List url:   " $ListURL `n"- - -"
                    $LimageUrl = ""
                    $LimageUrl = $list.ImageUrl   

                    # without 15 and with gif               
                    if( ($LimageUrl -Match "/_layouts/images/") -and ($LimageUrl -Match ".gif") )
                    {
                        Write-Host "Before:" $LimageUrl -ForegroundColor Yellow
                        $Add15 = $LimageUrl.Replace("/_layouts/images/" , "/_layouts/15/images/")
                        $gifReplace = $Add15.Replace(".gif" , ".png?rev=23")
                        $list.ImageUrl = $gifReplace 
                            ##
                            $list.Update()
                            ##
                        Write-Host "After: " $list.ImageUrl `n`n -ForegroundColor Cyan                        
                    }
                    # without 15 and with png
                    if( ($LimageUrl -Match "/_layouts/images/") -and ($LimageUrl -Match ".png") )
                    {
                        Write-Host "Before:" $LimageUrl -ForegroundColor DarkYellow
                        $Add15 = $LimageUrl.Replace("/_layouts/images/" , "/_layouts/15/images/")
                        $pngRevAdd = $Add15.Replace(".png" , ".png?rev=23")
                        $list.ImageUrl = $pngRevAdd
                            ##
                            $list.Update()
                            ##
                        Write-Host "After: " $list.ImageUrl `n`n -ForegroundColor Cyan

                    }
                }
            }
        }
    }
}
1
  • I found this really useful, but i noticed that the template BLOG still uses gifs. Easily fixed with a if/else condition to check if the current webtemplate is "BLOG" or not. Dec 22, 2016 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.