SharePoint – Search Slow opening documents

January 25, 2015

At the moment I have an problem in a certain side collection. Where the search result page appears quickly.

But when clicking any of the results to open a document, it takes more then 5 seconds Sad smile

So the next step is to see if a full Crawl of the search database, does not solve the problem.

Solution :

Go to Central Adminstration

clip_image002

Next go to Manage service applications –> Search Service Application

image

Go to Local SharePoint Sites and select Full Crawl from the dropdown menu.

There are more interesting options in the side menu.

Or you can use PowerShell to do the same.

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
        
# Get current Status
Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | select Name, CrawlStatus



Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | ForEach-Object {
    if ($_.CrawlStatus -ne "Idle")
    {
        Write-Host "Stopping currently running crawl for content source $($_.Name)..."
    #    $_.StopCrawl()
        
        do { Start-Sleep -Seconds 1 }
        while ($_.CrawlStatus -ne "Idle")
    }
    
    Write-Host "Starting full crawl for content source $($_.Name)..."
    # $_.StartFullCrawl()
}

After starting the Full Crawl everything was working again Smile


Powershell – How to start SharePoint WorkFlows in bulk

January 17, 2015

Once in a while you need to start a SharePoint  workflow for a batch of list items.

Especially when you are developing and need to to test the workflow. Or you are importing a new set of data in a list where you don’t want to run the workflow on creation of the dataset.

In these occasions you are in need of a manual start of the workflow on the full dataset or a selection of items in the list.

Solution :

This example starts a workflow on a selection of items that I control by an input file.

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

start-spassignment -global

#Open the web site, list and the workflow
$site=get-spsite <a href="http://YourSite">http://YourSite</a>
$web=get-spweb "http://YourServerName/sites/YourSiteCollection/"

#Open the library or list and workflow association
$affected = $web.getlist(<a href="http:///Lists/YourList)">http://YourServerName/Lists/YourList)

</a># WF Name
$wfname="Your WF Name here !!!" 

$manager=$site.workflowmanager
$culture=[system.globalization.cultureinfo]::currentculture

$association=$affected.workflowassociations.getassociationbyname($wfname,$culture)
$data=$association.associationdata
$wfrunoption=[microsoft.sharepoint.workflow.spworkflowrunoptions]::synchronous

#Start workflow

#Input File with all ID's where the WF should be started for.
$Customers = Get-Content "D:\Customer_IDs.txt" 

Write-host $association.ID $association.Name
Write-host ""
      
Foreach ($ID in $Customers){

    Foreach ($item in $affected.items) {
     If ($item.ID -eq $ID){
        $site.workflowmanager.startworkflow($item,$association,$data,$wfrunoption).InternalState
    }
  }
}

stop-spassignment -global

rv association, data, affected, wfrunoption, item

Enjoy!


SharePoint – Monitor the Search service

January 14, 2015

Sometime when you hit a performance issue on your SharePoint Server.

This can be caused by the Search Service being to aggressive or taking too long to crawl the data.

Well using Powershell we can list the status and details of the Search Services.

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
        
Write-Host "Search Service Status ..."
Get-SPSearchService

Write-Host "Search Crawl Service details ..."
$crawlSource = Get-SPEnterpriseSearchCrawlContentSource `
                -SearchApplication (Get-SPEnterpriseSearchServiceApplication)

$crawlSource

 

Output will look like this.

image

Where you can see how long it took the last time and whether the service is still active or Idle.

Sometime the server is overloaded if the Crawl schedules take too long and are overlapping each other.

So this can give you a starting point for debugging Winking smile


How to Cancel a Workflow that has not completed Successfully

October 14, 2014

Continuing on this List WF that have not been completed Successfully

Well here is the script to Cancel Workflows that have not been completed.

CLS

$web = Get-SPWeb "http://www.YourSite.com/"
$web.AllowUnsafeUpdates = $true;    

#Your List Name
$list = $web.Lists["YourListName"]
$count = 0

#Loop through all Items in List then loop through all Workflows on each List Items.         
foreach ($listItem in $list.Items) 
{
    foreach ($workflow in $listItem.Workflows) 
    {
        #Disregard Completed Workflows 
        if($Workflow.InternalState -ne "Completed" -and  $Workflow.InternalState -notlike "Cancelled*")
        {
            # Cancel Workflows        
            [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($workflow)   
            Write-Host "Workflow cancelled for : " $Workflow.AssociationId " - " $Workflow.InternalState  " - "  $listitem.ID $listitem.Title $listitem.Title  
        }
    }
}
$web.AllowUnsafeUpdates = $false
$web.Dispose()

Enjoy !


How to list all Workflow Items that have not completed Succussfully

October 14, 2014

If have tons of Workflows running. But form time to time I have a number of WorkFlows running that did not complete successfully.

In order to investigate the which items it concerns I have this little PowerShell Script.

Once you know the Item ID you can go there and cancel the workflow process.

CLS

$web=get-spweb "http://www.yoursite.com/"

$list = $web.Lists["YourListName"]

write-host "# Records : " $list.ItemCount

$i = 0

foreach($wf in $list.WorkflowAssociations)
{

   if($wf.Name -eq "YourListName")
   {
       write-host $wf.Name " - " $wf.Id
       write-host ""

       foreach($listitem in $list.Items)
       {

          foreach($Workflow in $listitem.Workflows)
          {
            if($Workflow.InternalState -ne "Completed")
            {
             # if($Workflow.AssociationId -eq $wf.ParentAssociationId) # change to if needed
             # {
                 write-host $i $Workflow.AssociationId " - " $Workflow.InternalState  " - "  $listitem.ID $listitem.Title $listitem.Title
                 $i++
             # }
            }

          }
       }
   }
}

Later on I hope to create a Cancel WF PowerShell script. Well here it is


How to start a SharePoint Workflow using PowerShell

October 11, 2014

Ever needed to start a workflow for multiple List Items, or a selection of items.

This Example runs a WF on Customer Items in a list.

Well here we go :

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

start-spassignment -global
#
#Open the web site, list and the workflow

$site=get-spsite "www.SharePoint.com"
$web=get-spweb "www.SharePoint.com/YourSide"

#
#Open the library or list and workflow association
#
$affected = $web.getlist("http://www.SharePoint.com/Lists/Yourlist")
# WF Name
$wfname="Your Workflow" 

$manager=$site.workflowmanager
$culture=[system.globalization.cultureinfo]::currentculture

$association=$affected.workflowassociations.getassociationbyname($wfname,$culture)
$data=$association.associationdata
$wfrunoption=[microsoft.sharepoint.workflow.spworkflowrunoptions]::synchronous

#
#Start workflow
#
#File with all ID's where the WF should be started for.
#

$Customers = Get-Content "D:\Temp\_Customers.txt" 

Foreach ($ID in $Customers){

    foreach ($item in $affected.items) {

     If ($item["ID"] -eq $ID){
      Write-Host $item["ID"] 
       $site.workflowmanager.startworkflow($item,$association,$data,$wfrunoption)
    }
  }
}

stop-spassignment -global 

I hope it worked as well for you.


SharePoint List – Extract a MultiLine Text Field (HTML)

July 23, 2014

Ever wanted to extract a multiline text field from a SharePoint List.

And this in a fast way Smile

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$WebURL = "http://YourSite/"

#List
$listName = "YourList"

#Activity
$ID = "1"
$TextField = "Your MultiLine Text Field Name"

#Get the Web &amp; Lists using the SPQuery (fast way)
$Web = Get-SPWeb $WebURL

        #$WebUrl = $site.OpenWeb()
        $list = $web.Lists[$listName]

        $query = New-Object Microsoft.SharePoint.SPQuery

        $query.RowLimit = 100

        $query.Query = "<where><eq><fieldref name="ID" /><value type=" Number">"+$ID+"</value></eq></where>"

        $items = $list.GetItems($query)

            foreach($item in $items){

            Write-Host "ID = " $item.ID

            Write-Host "Activity ID : " $item.ID "-" $item.Title -nobr
            Write-Host ""

            Write-Host $Text
  }

Notice the CAML query that grabs the record ID first. That will speed up the process tremendously.

Enjoy!