Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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()
share|improve this question
    
have you at least on site? –  Salvatore Di Fazio Oct 4 '12 at 7:54
    
whats the error –  SharePointer Oct 4 '12 at 8:09
    
@yaron The error is already mentioned in the question. –  Ashish Oct 4 '12 at 9:36
    
@SalvatoreDiFazio I have hundreds of them in prod and dev respectively. –  Ashish Oct 4 '12 at 9:37
add comment

2 Answers

up vote 0 down vote accepted

Have you looked at Ravi script.

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

share|improve this answer
    
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 '12 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 '12 at 3:25
add comment

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() 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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