I’ve got a job to do, Im going to be working on upgrading a 2007 SharePoint environment with a huge amount of customisations.

the first task was run that Pre-Upgrade check, and along with the thousands of problems it threw up were a couple of interesting ones.

Firstly, Missing SiteTemplates.  Really How and more importantly WHERE, because it doesnt tell you, all I got was this

  • name = Unknown, language = 1053, template id = 1, count = 2, status = Missing

I don’t even have language 1053 installed.

Secondly “The following event receiver assembly(s) are referenced by the content, but they are not installed on the web server”. Again how does that happen ? and WHERE.

Thirdly “The following feature(s) are referenced by the content, but they are not installed on the web server”, there is a bit of a theme here, can you guess what it is, yes WHERE!

So the answer was quick see if anyone has done something like this and lets create an mashup of those scripts.  So I take no credit other than the skeleton of this script. (For the originals see links at bottom of page).

So this is the kind of script I threw together, it’s not necessarily finished, but I thought that it would be handy to at least post it and perhaps someone might find it handy.

This only spits information out and not that well, I could spend longer formatting it, I probably will at some point.  You will have to edit it according to your own requirements, you will know what they are when you run the upgrade. Also this doesn’t do everything it’s a start though.

 

 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")    
###############################################################
#Get Base Objects
###############################################################
function GetBaseObjects
{
    trap {"The WebApplication URL is invalid"}
    $script:wa=[Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($SiteUrl);
} 

###############################################################
#Main Processing Loop
############################################################### 

function ProcessWebApplication
{ 

    cls
    Write-Host "Starting Scan"
    $i=0;
    foreach ($site in $wa.Sites)
    {
        $siteCount=$wa.Sites.Count
           Write-Progress -id 1 -activity "Scanning SPSites" -status "Percent scanned: " -PercentComplete (($i / $siteCount)  * 100)
        $i++
        #Check for Missing Features
        foreach ($feature in $site.features) { 
            if ($feature.definition -eq $null) 
            { 
                write-host ("Missing site feature:" + $feature.DefinitionId  + ", " + $feature.parent )
            } 
        }
        foreach ($web in $site.AllWebs)
        {
            $ok=$true;
            $webCount=$site.AllWebs.Count
            #Check for this lang code as I have an 
	    #    unidentified Template in this lang code             
	    #Checking for lang rather than name as not sure whether 
            #    unidentified is stored as that or null or whatever
            if ($web.Language -eq "1053")
            {
                if($ok)
                {
                    Write-Host("SPWeb:" + $web.Url )
                    $ok=$false;
                }
                Write-Host("Langauge is set to 1053 possible missing template")
            }
            $lists = $web.Lists | where {$_.EventReceivers.Count -gt 0}
            foreach ($list in $lists) 
            {
                $evts = $list.EventReceivers 
                if ($evts.Count -gt 0) 
                {
                    foreach ($evt in $evts) 
                    {
                        $found=$false
                        if ($evt.Assembly -like "BinaryJam.SharePoint.EvRcExample1*") { $found=$true } 
                        if ($evt.Assembly -like "BinaryJam.SharePoint.EvRcExample2*") { $found=$true } 
                        if ($evt.Assembly -like "BinaryJam.SharePoint.EvRcExample3*") { $found=$true } 
                        if ($found)
                        {
                            if($ok)
                            {
                                Write-Host("SPWeb:" + $web.Url )
                                $ok=$false;
                            }
                            Write-Host("    " + $list.RootFolder.ServerRelativeUrl + ", " + $evt.Id + 
                                       ", " + $evt.Class  + ", " + $evt.Type) 

                        } 

                    }
                }
            } 

            $web.Dispose()
        }
        $site.Dispose()
    }
    "Completed Scan"
    $web=$null
    $site=$null
} 

###############################################################
#Clean up your room
###############################################################
function CleanUp
{
    trap{continue}
    $script:wa=$null
} 

###############################################################
# Validate args
###############################################################
function ValidateArgs($arg)
{
    if ($arg.Length -ne 1 -or $arg[0] -eq "-?" )
    {
        Write-Host "Usage: .FindingMissingStuff.ps1 <spsiteurl>";
        return $false;
    }
    $script:SiteUrl = $arg[0];
    return $true
} 

###############################################################
# Main
###############################################################
cls
if (ValidateArgs $args)
{
    GetBaseObjects
    ProcessWebApplication
    CleanUp
}


 

These are the two sites I gleaned the salient information from and I just embedded it within my own powershell structure I use for most my stuff.

 

http://blogs.blackmarble.co.uk/blogs/rhepworth/archive/2010/11/19/powershell-to-find-missing-features-in-sharepoint-2010.aspx

http://blog.falchionconsulting.com/index.php/2009/03/deleting-orphaned-event-receivers-using-powershell

Advertisements