{"id":124,"date":"2022-05-23T10:31:24","date_gmt":"2022-05-23T07:31:24","guid":{"rendered":"http:\/\/foonk.ddns.net\/?p=124"},"modified":"2022-09-26T13:26:00","modified_gmt":"2022-09-26T10:26:00","slug":"%d0%be%d1%87%d0%b8%d1%81%d1%82%d0%b8%d1%82%d1%8c-wss_content-%d0%be%d1%82-missingsetupfiles-missingwebpart-missingfeatures","status":"publish","type":"post","link":"https:\/\/kb.astrocroc.com\/?p=124","title":{"rendered":"\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c WSS_Content \u043e\u0442 MissingSetupFiles, MissingWebpart, MissingFeatures"},"content":{"rendered":"\n<p>\u200b\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 Sharepoint \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u041c\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 Sharepoint, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0447\u0442\u043e \u0432 \u0411\u0414 WSS_Content \u0438\u043c\u0435\u044e\u0442\u0441\u044f&nbsp;MissingSetupFiles, MissingWebpart, MissingFeatures.&nbsp;<\/p>\n\n\n\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0444\u0430\u0439\u043b Step 1.ps1, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0444\u0430\u0439\u043b \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0445&nbsp;MissingSetupFiles, MissingWebpart, MissingFeatures.<\/p>\n\n\n\n<p><strong>step 1.ps1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">$wa = Get-SPWebApplication &quot;https:\/\/portal.pac.ru&quot;\n$outputPath = &quot;C:\\\\Users\\spfarm\\Desktop\\Cleanup_missing_features\\Test_Wss_Content_MissingAssembly_{0}.txt&quot; -f (Get-Date -Format hhmmss)\n$dbName = &quot;WSS_Content&quot;\n$slqServer = &quot;sharSQL&quot;\nTest-SPContentDatabase -Name $dbName -WebApplication $wa -ServerInstance $slqServer -ShowLocation:$true -ExtendedCheck:$false | Out-File $outputPath <\/code><\/pre>\n\n\n\n<p>\u0414\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 MissingFeatures \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0430\u0439\u043b Step 2.ps1, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u043c&nbsp;$featureID \u0438&nbsp;$siteID.<\/p>\n\n\n\n<p><strong>step 2.ps1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">$featureID = &quot;75e8e0cf-9b94-4803-93bb-6a9bb93995ae&quot;\n$siteID = &quot;f2f6396a-6e72-4747-b5c0-3c7efd604dab&quot;   \n\n#Display site information\n$site = Get-SPSite $siteID  \nWrite-Host &quot;Checking Site:&quot; $site.Url\n\n#Remove the feature from all subsites\nForEach ($web in $Site.AllWebs)\n {\n     If($web.Features[$featureID])\n         {\n             Write-Host &quot;`nFound Feature $featureID in web:&quot;$Web.Url&quot;`nRemoving feature&quot;\n             $web.Features.Remove($featureID, $true)\n         }\n         else\n         {\n             Write-Host &quot;`nDid not find feature $featureID in web:&quot; $Web.Url\n         }  \n }\n\n#Remove the feature from the site collection\nIf ($Site.Features[$featureID])\n {\n     Write-Host &quot;`nFound feature $featureID in site:&quot;$site.Url&quot;`nRemoving Feature&quot;\n     $site.Features.Remove($featureID, $true)\n }\n else\n {\n     Write-Host &quot;Did not find feature $featureID in site:&quot; $site.Url\n }<\/code><\/pre>\n\n\n\n<p>\u0417\u0430\u0442\u0435\u043c \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c Step 3.ps1, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u043c FeatureID \u0432 \u0441\u0442\u0440\u043e\u043a\u0435<\/p>\n\n\n\n<p>Remove-SPFeatureFromContentDB -ContentDB &#171;Wss_Content&#187; -FeatureId &#171;75e8e0cf-9b94-4803-93bb-6a9bb93995ae&#187; \u2013ReportOnly<\/p>\n\n\n\n<p><strong>step 3.ps1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">\n\nfunction Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly)\n{\n    $db = Get-SPDatabase | where { $_.Name -eq $ContentDb }\n    [bool]$report = $false\n    if ($ReportOnly) { $report = $true }\n    \n    $db.Sites | ForEach-Object {\n        \n        Remove-SPFeature -obj $_ -objName &quot;site collection&quot; -featId $FeatureId -report $report\n                \n        $_ | Get-SPWeb -Limit all | ForEach-Object {\n            \n            Remove-SPFeature -obj $_ -objName &quot;site&quot; -featId $FeatureId -report $report\n        }\n    }\n}\n\nfunction Remove-SPFeature($obj, $objName, $featId, [bool]$report)\n{\n    $feature = $obj.Features[$featId]\n    \n    if ($feature -ne $null) {\n        if ($report) {\n            write-host &quot;Feature found in&quot; $objName &quot;:&quot; $obj.Url -foregroundcolor Red\n        }\n        else\n        {\n            try {\n                $obj.Features.Remove($feature.DefinitionId, $true)\n                write-host &quot;Feature successfully removed from&quot; $objName &quot;:&quot; $obj.Url -foregroundcolor Red\n            }\n            catch {\n                write-host &quot;There has been an error trying to remove the feature:&quot; $_\n            }\n        }\n    }\n    else {\n        #write-host &quot;Feature ID specified does not exist in&quot; $objName &quot;:&quot; $obj.Url\n    }\n}\n\nRemove-SPFeatureFromContentDB -ContentDB &quot;Wss_Content&quot; -FeatureId &quot;75e8e0cf-9b94-4803-93bb-6a9bb93995ae&quot; \u2013ReportOnly<\/code><\/pre>\n\n\n\n<p>\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 Step 3.ps1<\/p>\n\n\n\n<p>\u0422\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 MissingFeature<\/p>\n\n\n\n<p>\u0414\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f&nbsp;MissingSetupFiles \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b&nbsp;Remove missing setup files.ps1, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u043c $SetupFile&nbsp;<\/p>\n\n\n\n<p>$SetupFile=&#187;Features\\TestWPproj_Feature1\\TestWP\\TestWP.webpart&#187;<\/p>\n\n\n\n<p><strong>Remove missing setup files.ps1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue\n \nFunction Run-SQLScript($SQLServer, $SQLDatabase, $SQLQuery)\n{\n    $ConnectionString = &quot;Server =&quot; + $SQLServer + &quot;; Database =&quot; + $SQLDatabase + &quot;; Integrated Security = True&quot;\n    $Connection = new-object system.data.SqlClient.SQLConnection($ConnectionString)\n    $Command = new-object system.data.sqlclient.sqlcommand($SQLQuery,$Connection)\n    $Connection.Open()\n    $Adapter = New-Object System.Data.sqlclient.sqlDataAdapter $Command\n    $Dataset = New-Object System.Data.DataSet\n    $Adapter.Fill($Dataset)\n    $Connection.Close()\n    $Dataset.Tables[0]\n}\n \n#Define configuration parameters\n$Server=&quot;sharSQL&quot;\n$Database=&quot;WSS_Content&quot;\n$SetupFile=&quot;Features\\TestWPproj_Feature1\\TestWP\\TestWP.webpart&quot;\n \n#Query SQL Server content Database to get information about the MissingFiles\n$Query = &quot;SELECT * from AllDocs where SetupPath like &#039;&quot;+$SetupFile+&quot;&#039;&quot;\n$QueryResults = @(Run-SQLScript -SQLServer $Server -SQLDatabase $Database -SQLQuery $Query | select Id, SiteId, WebId)\n \n#Iterate through results\nforeach ($Result in $QueryResults)\n{\n    if($Result.id -ne $Null)\n    {\n        $Site = Get-SPSite -Limit all | where { $_.Id -eq $Result.SiteId }\n        $Web = $Site | Get-SPWeb -Limit all | where { $_.Id -eq $Result.WebId }\n \n        #Get the URL of the file which is referring the feature\n        $File = $web.GetFile([Guid]$Result.Id)\n        write-host &quot;$($Web.URL)\/$($File.Url)&quot; -foregroundcolor green\n         \n        $File.delete()\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u0418 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e MissingSetupFile<\/p>\n\n\n\n<p>\u0414\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f&nbsp;MissingWebpart&nbsp;\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b&nbsp;Remove missing webpart.ps1, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u043c $webPartID<\/p>\n\n\n\n<p>$webPartID=&#187;6817d0b2-eccd-d695-340d-82e13c030b09&#8243;<\/p>\n\n\n\n<p><strong>Remove missing webpart.ps1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue\n \nFunction Run-SQLScript($SQLServer, $SQLDatabase, $SQLQuery)\n{\n    $ConnectionString = &quot;Server =&quot; + $SQLServer + &quot;; Database =&quot; + $SQLDatabase + &quot;; Integrated Security = True&quot;\n    $Connection = new-object system.data.SqlClient.SQLConnection($ConnectionString)\n    $Command = new-object system.data.sqlclient.sqlcommand($SQLQuery,$Connection)\n    $Connection.Open()\n    $Adapter = New-Object System.Data.sqlclient.sqlDataAdapter $Command\n    $Dataset = New-Object System.Data.DataSet\n    $Adapter.Fill($Dataset)\n    $Connection.Close()\n    $Dataset.Tables[0]\n}\n \n#Define configuration parameters\n$Database=&quot;WSS_Content&quot;\n$webPartID=&quot;6817d0b2-eccd-d695-340d-82e13c030b09&quot;\n \n#Get the Database Server from Database\n$server = (Get-SPDatabase |?{ $_.name -eq $Database}).server\n \n#Query SQL Server content Database to get information about the MissingFiles\n$Query = &quot;SELECT distinct ID,SiteId,DirName, LeafName, WebId, ListId from dbo.AllDocs where id in (select tp_PageUrlID from dbo.AllWebParts where tp_WebPartTypeId =&#039;$($webPartID)&#039;)&quot;\n$QueryResults = Run-SQLScript -SQLServer $Server -SQLDatabase $Database -SQLQuery $Query | select Id , SiteId, DirName, LeafName, WebId, ListId\n \n#Iterate through results\nforeach ($Result in $QueryResults)\n{\n    if($Result.id -ne $Null)\n    {\n        $Site = Get-SPSite -Limit all | where { $_.Id -eq $Result.SiteId }\n        $Web = $Site | Get-SPWeb -Limit all | where { $_.Id -eq $Result.WebId }\n \n        #Get the URL of the file which is referring the web part\n        $File = $web.GetFile([Guid]$Result.Id)\n        write-host &quot;$($Web.URL)\/$($File.Url)&quot; -foregroundcolor green\n\t\t\n\t\t$File.delete()\n    }\n}\n\n\n<\/code><\/pre>\n\n\n\n<p>\u0418 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e MissingWebpart<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 Sharepoint \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u041c\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 Sharepoint, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0447\u0442\u043e \u0432 \u0411\u0414 WSS_Content \u0438\u043c\u0435\u044e\u0442\u0441\u044f&nbsp;MissingSetupFiles, MissingWebpart, MissingFeatures.&nbsp; \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0444\u0430\u0439\u043b Step 1.ps1, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0444\u0430\u0439\u043b \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0445&nbsp;MissingSetupFiles, MissingWebpart, MissingFeatures. step 1.ps1 \u0414\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 MissingFeatures \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0430\u0439\u043b Step 2.ps1, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u043c&nbsp;$featureID \u0438&nbsp;$siteID. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[33],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-sharepoint","tag-sharepoint"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=124"}],"version-history":[{"count":2,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/124\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}