1

I am trying to update the Site Logo Url for all the sites in my web application with powershell. The script executes correctly in my dev environment but fails to execute in production and gives an error

Exception calling "Update" with "0" argument(s): "Object reference not set to an instance of an object."
At D:\Set-WebAppLogoUrl.ps1:28 char:11
+     $_.Update <<<< ();
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I logged in the system with a farm account but still get the error. Any help would be appreciated. Below is my PS Script I am trying to execute:

$siteUrl = "http://mysite/sites/it"
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl) 
$spWebApp = $rootSite.WebApplication 

foreach($site in $spWebApp.Sites) { 
    $site.AllWebs | foreach { 
        $_.SiteLogoUrl = "/PublishingImages/companylogo.gif";
        $_.Update();
    }
}
$rootSite.Dispose()
4
  • have you at least on site? Oct 4, 2012 at 7:54
  • whats the error Oct 4, 2012 at 8:09
  • @yaron The error is already mentioned in the question.
    – Ashish
    Oct 4, 2012 at 9:36
  • @SalvatoreDiFazio I have hundreds of them in prod and dev respectively.
    – Ashish
    Oct 4, 2012 at 9:37

2 Answers 2

0

Have you looked at Ravi script.

http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/67f901e9-b4d7-4bee-87c9-0a585e61405e

2
  • The script mentioned there is the same I used except the fact that my script does it for all site collections, sites and sub-sites in my web application and the script in post does it for specified site collection, site and sub-sites.
    – Ashish
    Oct 4, 2012 at 9:39
  • I had issues with my production environment which was causing the problems. I resolved the issues with my operations team and the script ran like a charm. Marked as answer since the above script was the one I actually ran.
    – Ashish
    Oct 7, 2012 at 3:25
0

My guess would be that you have a site collection which is in a state where it doesn't have any sites.

I'd change the scipt to :

$siteUrl = "http://mysite/sites/it" 
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)  
$spWebApp = $rootSite.WebApplication  

foreach($site in $spWebApp.Sites) {  
    $site.AllWebs | foreach {  
        if ($_ -ne $null) {
            $_.SiteLogoUrl = "/PublishingImages/companylogo.gif"; 
            $_.Update(); 
        }
    } 
} 
$rootSite.Dispose() 

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.