码迷,mamicode.com
首页 > 其他好文 > 详细

Missing server side dependencies in SharePoint 2013

时间:2015-05-04 11:53:42      阅读:564      评论:0      收藏:0      [点我收藏+]

标签:troubleshooting

The follow issues in Health Analyzer:

技术分享

[MissingWebPart]

WebPart class [40209021-7bb0-e465-2576-abddac43061b] (class [CommunityForumTopics.WebParts.ForumTopicsWebPart.ForumTopicsWebPart] from assembly [CommunityForumTopics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4e4625abaca6859d]) is referenced [73] times in the database [WSS_Content], but is not installed on the current farm. Please install any feature/solution which contains this web part. One or more web parts are referenced in the database [WSS_Content], but are not installed on the current farm. Please install any feature or solution which contains these web parts.

[MissingSetupFile]

File [Features\image\GoToTop_normal_icon.png] is referenced [1] times in the database [WSS_Content], but is not installed on the current farm. Please install any feature/solution which contains this file. One or more setup files are referenced in the database [WSS_Content], but are not installed on the current farm. Please install any feature or solution which contains these files.

[MissingFeature]

Database [WSS_Content] has reference(s) to a missing feature: Id = [8096285f-1463-42c7-82b7-f745e5bacf29], Name = [My Feature], Description = [], Install Location = [Test-MyFeature]. The feature with Id 8096285f-1463-42c7-82b7-f745e5bacf29 is referenced in the database [WSS_Content], but is not installed on the current farm. The missing feature may cause upgrade to fail. Please install any solution which contains the feature and restart upgrade if necessary.

How to fix it?

[MissingFeature]

Note: This message reports a content database name and feature ID ,but not the sites or site collections where the feature exists. In addition to this, even if you did know where the feature was activated, it will not appear anywhere in the UI for you to deactivate because the solution has been removed from the farm.

The following PowerShell script will interrogate a specified content database and feature ID and do two things:

  1. Produce a report in the PowerShell console showing which sites or site collections contain the offending feature.
  2. Forcibly deactivate the feature from the applicable sites or site collections.
function Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly)
{
    $db = Get-SPDatabase | where { $_.Name -eq $ContentDb }
    [bool]$report = $false
    if ($ReportOnly) { $report = $true }
    
    $db.Sites | ForEach-Object {
        
        Remove-SPFeature -obj $_ -objName "site collection" -featId $FeatureId -report $report
                
        $_ | Get-SPWeb -Limit all | ForEach-Object {
            
            Remove-SPFeature -obj $_ -objName "site" -featId $FeatureId -report $report
        }
    }
}

function Remove-SPFeature($obj, $objName, $featId, [bool]$report)
{
    $feature = $obj.Features[$featId]
    
    if ($feature -ne $null) {
        if ($report) {
            write-host "Feature found in" $objName ":" $obj.Url -foregroundcolor Red
        }
        else
        {
            try {
                $obj.Features.Remove($feature.DefinitionId, $true)
                write-host "Feature successfully removed from" $objName ":" $obj.Url -foregroundcolor Red
            }
            catch {
                write-host "There has been an error trying to remove the feature:" $_
            }
        }
    }
    else {
        #write-host "Feature ID specified does not exist in" $objName ":" $obj.Url
    }

}


 # it will find the feature 

 Remove-SPFeatureFromContentDB -ContentDB "WSS_Content" -FeatureId "<span style="color:#3366ff;">8096285f-1463-42c7-82b7-f745e5bacf29</span>" -ReportOnly

 # it will remove the feature directly


 Remove-SPFeatureFromContentDB -ContentDB "WSS_Content" -FeatureId "<span style="color:#3366ff;">8096285f-1463-42c7-82b7-f745e5bacf29</span>" 
 


[MissingWebPart]

Note: These events are logged because the migrated SharePoint  Sites contains some references to custom WebPart files and the linked feature/solution are not installed in the Farm

To safely remove the webparts and references, we need to be able to identify their specific location on the Farm

# the name of the Db server
$DBserver = "tristan-db"
#<strong>[path\missingwebparts.txt]</strong> is a input file you need to create based on the <strong>[MissingWebPart]</strong> errors that you get on the SharePoint Health Analyzer
$path = "C:\Users\tristan-desktop\Script\MissingHealth.txt" 
#Set Variables
$input = @(Get-Content $path)
 

#Declare Log File
Function StartTracing
{
    $LogTime = Get-Date -Format yyyy-MM-dd_h-mm
    $script:LogFile = "MissingWebPartOutput-$LogTime.csv"
    Start-Transcript -Path $LogFile -Force
}
 
#Declare SQL Query function
function Run-SQLQuery ($SqlServer, $SqlDatabase, $SqlQuery)
{
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server =" + $SqlServer + "; Database =" + $SqlDatabase + "; Integrated Security = True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
}
 
 
function GetWebPartDetails ($wpid, $DBname)
    {
    #Define SQL Query and set in Variable
    $Query =  "SELECT * from AllDocs inner join AllWebParts on AllDocs.Id = AllWebParts.tp_PageUrlID where AllWebParts.tp_WebPartTypeID = '"+$wpid+"'"
 
    #Runing SQL Query to get information about Assembly (looking in EventReceiver Table) and store it in a Table
    $QueryReturn = @(Run-SQLQuery -SqlServer $DBserver -SqlDatabase $DBname -SqlQuery $Query | select Id, SiteId, DirName, LeafName, WebId, ListId, tp_ZoneID, tp_DisplayName)
 
    #Actions for each element in the table returned
        foreach ($event in $QueryReturn)
        {
            if ($event.id -ne $null)
                {
                #Get Site URL
                $site = Get-SPSite -Limit all | where {$_.Id -eq $event.SiteId}
    
write-host "==================================================================="
                write-host $site.Url -nonewline -foregroundcolor green 
                write-host "/" $event.DirName -nonewline -foregroundcolor green 
                write-host "/"$event.LeafName  -foregroundcolor green 
                }
         }
    }
 
 Start Logging
 StartTracing
 
#Log the CVS Column Title Line
 write-host "WebPartID;PageUrl;MaintenanceUrl;WpZoneID" -foregroundcolor Red
 
 foreach ($event in $input)
    {
     $wpid = $event.split(";")[0]
     $DBname = $event.split(";")[1]
     GetWebPartDetails $wpid $dbname
    }
    
 Stop Logging
 Stop-Transcript

run the cmd:

1. it will found ou all the relevant pags implemented the webpart

2. then you need to delete the webpart in the exactly page one by one by manual

3. clear the history version of the page

4. finally, remember to clear the recycle bin

you can run the cmd again to check the result, it will not find the same issues.

[MissingSetFile]

Note: These events are logged because the migrated SharePoint 2013 Sites contains some references to custom Feature files and the linked feature are not installed in the Farm.

The easy solution is obviously to install the features related to those files, but if you are in the same situation as me, you don‘t really need the features anymore and you just want the database to be clean and get rid of these events.

 DBserver = "tristan-db"
 $path = "C:\Users\Script\MissingHealth_Set.txt"

  
 #Set Variables  
 $input = @(Get-Content $path)  
 #Addin SharePoint2010 PowerShell Snapin  
 Add-PSSnapin -Name Microsoft.SharePoint.PowerShell  
 #Declare Log File  
 Function StartTracing  
 {  
   $LogTime = Get-Date -Format yyyy-MM-dd_h-mm  
   $script:LogFile = "MissingSetupFileOutput-$LogTime.txt"  
   Start-Transcript -Path $LogFile -Force  
 }  
 #Declare SQL Query function  
 function Run-SQLQuery ($SqlServer, $SqlDatabase, $SqlQuery)  
 {  
   $SqlConnection = New-Object System.Data.SqlClient.SqlConnection  
   $SqlConnection.ConnectionString = "Server =" + $SqlServer + "; Database =" + $SqlDatabase + "; Integrated Security = True"  
   $SqlCmd = New-Object System.Data.SqlClient.SqlCommand  
   $SqlCmd.CommandText = $SqlQuery  
   $SqlCmd.Connection = $SqlConnection  
   $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter  
   $SqlAdapter.SelectCommand = $SqlCmd  
   $DataSet = New-Object System.Data.DataSet  
   $SqlAdapter.Fill($DataSet)  
   $SqlConnection.Close()  
   $DataSet.Tables[0]  
 }  
 #Declare the GetFileUrl function  
 function GetFileUrl ($filepath, $DBname)  
 {  
     #Define SQL Query and set in Variable  
     $Query = "SELECT * from AllDocs where SetupPath = '"+$filepath+"'"  
     #Runing SQL Query to get information about the MissingFiles and store it in a Table  
     $QueryReturn = @(Run-SQLQuery -SqlServer $DBserver -SqlDatabase $DBname -SqlQuery $Query | select Id, SiteId, DirName, LeafName, WebId, ListId)  
     foreach ($event in $QueryReturn)  
       {  
         if ($event.id -ne $null)  
         {  
         $site = Get-SPSite -Limit all | where { $_.Id -eq $event.SiteId }  
         #get the URL of the Web:  
         $web = $site | Get-SPWeb -Limit all | where { $_.Id -eq $event.WebId }  
         #Write the SPWeb URL to host  
         Write-Host $filepath -nonewline -foregroundcolor yellow  
         Write-Host ";" -nonewline  
         write-host $web.Url -NoNewline -foregroundcolor green  
         #get the URL of the actual file:  
         $file = $web.GetFile([Guid]$event.Id)  
         #Write the relative URL to host  
         write-host "/" -nonewline -foregroundcolor green  
         write-host $file.Url -foregroundcolor green 
         #$file.delete()  # you can delete the file with this code
         }  
       }  
 }  
 #Start Logging  
 StartTracing  
 #Log the CVS Column Title Line  
 write-host "MissingSetupFile;Url" -foregroundcolor Red  
 foreach ($event in $input)  
   {  
   $filepath = $event.split(";")[0]  
   $DBname = $event.split(";")[1]  
   #call Function  
   GetFileUrl $filepath $dbname  
   }  
 #Stop Logging  
 Stop-Transcript  

Note: If you want to get rid of all files unused, update the above script by adding the line $file.delete() after the line write-host $file.Url -foregroundcolor green  in the IF statement 
(to be used at your own risk - I would strongly recommend to first analyse the report generated before updating the script with the delete option, to avoid removing important files.)


More in detail : http://etienne-sharepoint.blogspot.jp/2011/10/solving-missingsetupfile-errors-from.html, http://get-spscripts.com/2011/06/removing-features-from-content-database.html










Missing server side dependencies in SharePoint 2013

标签:troubleshooting

原文地址:http://blog.csdn.net/tristan_dong/article/details/45477849

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!