Showing posts with label PowerShell Script. Show all posts
Showing posts with label PowerShell Script. Show all posts

Monday, 27 January 2014

MissingWebPart Error in SharePoint 2010

Hi all,

Today I found useful cmdlets to diagnose and clear those errors in the Content DB of my SharePoint 2010 Farm.

How to proceed:

Step 1: Inspect the DB
-          Test-SPContentDatabase -name <ContentDB_Name> -webapplication <Web App URL>

Step 2:
-          Select the WebPart Class GUID

Step 3:
           -     Create the SQL Function and execute it into PowerShell:

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]
}

-          Run this command with the related WebPart Class GUID:

Run-SQLQuery -SqlServer "SRV_DATABASE" -SqlDatabase "SharePoint_Content_sharepointWorkgroup17" -SqlQuery "SELECT * from AllDocs inner join AllWebParts on AllDocs.Id = AllWebParts.tp_PageUrlID where AllWebParts.tp_WebPartTypeID = '9812863c-ee62-dab6-57f5-79e9d4d36022'" | select Id, SiteId, DirName, LeafName, WebId, ListId, tp_ZoneID, tp_DisplayName | Format-List


Step 4:
-          The result will give the below info, with the URL where the Missing Web Part is located:

Id                         : a5da7b36-083f-4d07-b50b-8f1fc8d7bbe9
SiteId                   : 53061278-8b1d-4d6d-9dce-8568f90c5574
DirName              : Sites/WW12000012/Sandbox/TestWSServiceLevelDashboard
LeafName            : default.aspx
WebId                 : 2ab691b1-0d74-4bf2-9524-c6b1d969cfac
ListId                   :
tp_ZoneID           : Left
tp_DisplayName  :



                  Adding at the end of the URL "?contents=1" will let SharePoint to show the "Web Part Page"


-          So, here are the steps that I follow to remove the “ErrorWebPart”:

1- select the Error rows
2- click on “Close” to set them as “No” for the “Open on Page?” column
3- select the same Error rows then Delete them



Step 5:
-          Execute again the “Test-SPContentDatabase” to check that all entries for the MissingWebPart are gone.




That's all folks




How to replace an existing URL located in the Top Navigation Bar

Hi All,

Today's request is to replace the Hyperlink in the navigator bar, as the referenced site URL has changed.




And last but not least, the request is to change this hyperlink to all sites inside the Web App: more than 1800 Site Collection.


This is the used Code:

#----------------------------------------------------------------------
#Below the code to update the topnavigationbar
#  for all Site Collection of the mentioned Web Application .
# Author : Marc Mathot
# Date: November 2013
#----------------------------------------------------------------------
$Webs = Get-SPSite -WebApplication "http://SharePoint.Contoso.com"  -limit ALL | Get-SPWeb -limit all

Foreach($Web in $Webs)
{
$TN = $Web.Navigation.TopNavigationBar | Where-Object {$_.Title -eq "Landing Page & Wiki"}
if ($TN.url -like "http://SharePoint.Contoso.com*")
{
   write-host "Updating $($Web.url)"
  “Updating $($Web.url), $($TN.Url)” | out-file D:\temp\LandingPageUpdate.csv   -append
    $TN.Url = "http://NewSharePoint.Contoso.com/Pages/LandingPageWikiDefault.aspx"
    $TN.update()
}
}
#----------------------------------------------------------------------

Also, in parallel, I had to modify the template used to create the new sites into this Web App.
Doing this will avoid having to run this script periodically to correct the changes.




That's all folks

Monday, 9 July 2012

How to list all the Site Collection Admins into a specific Web Application in Shp2007


Hi all,

Today’s challenge, is to list all the SCA’s of a Web App.

With google, I found a nice simple post on "The Frog Pond of Technology" with a little powershell script.
Then, I found a link to the Brian T. Jackett TechNet Script Repository , and tested his script, with a little change, explained by Tasha’s feedback in the first link (I got the same blank names).

So, hereunder is the script that I’m now using to grab all the SCA’s in the needed WA.

########################################################### #SP_Display-SiteCollectionAdmins1.ps1 -URL # #Author: Brian T. Jackett #Last Modified Date: Mar. 25, 2011 # #Display all site collection admins for all site collections # within a web application. ########################################################### [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint') #DECLARE VARIABLES [string]$siteUrl = $args[0] function GetMissingParameter { $script:siteUrl = Read-Host "Enter Site URL" } ############ # MAIN ############ #IF MISSING PARM FOR SITE URL, ASK FOR INPUT TO FILL if($args.length -eq 0) { GetMissingParameter } $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl) $spWebApp = $rootSite.WebApplication foreach($site in $spWebApp.Sites) { foreach($siteAdmin in $site.RootWeb.SiteAdministrators) { Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.Name)" Write-Output "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.Name)" |Out-File -encoding default -append } $site.Dispose() } $rootSite.Dispose()


nb: added the output to a file



I didn’t test this script in SharePoint 2010, but it is said that this script in object model will work for 2007 and 2010.


That's all folks.