Sunday, June 22, 2014

Disable Throttling Limit for specific lists

Hi All,

Recently, we had the requirement to disable the large query window for entire web application as it is having some performance issues over content database.

But, we have some large lists used by business, which is stopping us to enable the throttling setting at the web application level.

We have the propery at the list level to disable throttling limit for disabling throttling limit so that these lists will not have any impact though we disable the large window time at web application level.

The propery name is "EnableThrottling" which we need to set it to false.

Here is the simple powershell script with the example.

 
$web=get-spweb http://sitecollectionurl
$list=$web.Lists[“ListName”];
$list.EnableThrottling=$false;
$list.update();

Workflow Instance Report across site collection using Powershell script

Hi All,

I have written the script to retrieve the workflow instances that associated across a specific site collection.

The script will iterate through each item in the list/library for all sub sites in the site collection and provides the workflows associated with the status, status url, item id, workflow name, workflow instance id.

 
param ([boolean] $writeToFile = $true)
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Add-Type @'
 public class workflowItem
 {
   public string weburl;
   public string ListURL;
   public string Item;
   public string workflowname;
   public string status;
   public string InstanceId;
   public string url;
 }
'@

$itemsCollection = New-Object 'System.Collections.Generic.List[System.Object]';
$exportfile = $currentdatetime = get-date -format "yyyy-MM-d.hh-mm-ss";
$exportVersionLocation=$exportfolder+"\workflowstats"+$exportfile+".csv"

#Counter variables
 $webcount = 0
 $listcount = 0
 $associationcount = 0

$sitename =  Read-Host "Enter site collection url"
$site=Get-SPSite -Identity $sitename

$webs=$site.Allwebs

if($webs.count -ge 1)
{

foreach($web in $site.Allwebs)
{


 write-host $web 
 #Grab all lists in the current web
 $lists = $web.Lists
 foreach($list in $lists)
 {
 $associations = @()
    #Get all workflows that are associated with the current list
             foreach($listassociation in $list.WorkflowAssociations)
 {
 $associations += $($listassociation.name)
 }
 $listcount +=1

 if($associations.count -ge 1 -and $list.items.count -ge 1)
 {

 foreach($item in $list.items)
  {

foreach($wf in $item.workflows)
    {

     $wfItem = New-Object workflowItem
     $wfItem.weburl=$web.url
     $wfItem.ListURL=$list.Title
     $wfitem.Item=$item.Title
     $ass1=$wf.parentassociation
     $wfItem.workflowname=$ass1.Name
     $wfItem.status=$wf.InternalState
     $wfitem.InstanceId=$wf.InstanceID.Tostring()
     $wfitem.url=$wf.StatusUrl
     $itemsCollection.Add($wfItem);
     
    }
 
   }

 
 }

 }
}
 $webcount +=1

 $web.Dispose()
 }

$itemsCollection | export-csv "$exportVersionLocation" -noType
 
The csv file will be generated in the root directory where the script placed and executed,

Large List items paging using ListItemCollectionPosition

Hi All,

I got the requirement to iterate large list items which are above throttling limits. Since we get the throttling exception when try to retrive items using caml query through standard process using server object model.

I used the "ListItemCollectionPosition" object to show items in the paging view.


 
$weburl=Read-Host "Enter site url"
$web = Get-SPWeb -Identity $weburl
$listname=Read-Host "Enter the list name"
$list = $web.Lists["$listname"]
if($list -ne $null)

{
write-host $list.Title
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.RowLimit = 10
$caml = '' 
$spQuery.Query = $caml 

do
{
    
    $listItems = $list.GetItems($spQuery)
    
    Write-Host $listItems.ListItemCollectionPosition.PagingInfo
    $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
    foreach($item in $listItems)
    {
        Write-Host $item.Title
        
    }
}
while ($spQuery.ListItemCollectionPosition -ne $null)
}

else
{
write-host "List does not exist"
}

Cancel Workflow Instances using powershell script

Hi All,

Recently, I worked on the requirement to terminate the running workflow instances associtated to the specific list using powershell script.

I used WorkflowManager and then Cancel method with passiing the workflow instance class,

Here  I terminated the workflows for which the workflow status is running.

here is the script.

 
#Site URL
$siteurl=Read-Host "Enter Site URL"
$web = Get-SPWeb $siteurl
$web.AllowUnsafeUpdates = $true;    

#List Name
$listname=Read-Host "Enter list Name"
$list = $web.Lists["$listname"];

if($list -ne $null)
{
# Iterate through all Items in List and all Workflows on Items.         
foreach ($item in $list.Items) {
foreach ($wf in $item.Workflows) {

#Cancel Workflows      

if($wf.InternalState - eq 'Running')
{  
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);      
}
}
}
$web.Dispose();
}
else
{
 write-host "List does not exist"
}

Specific feature Activated sites report using Powershell

Hi All,

when you got the requirement to know the list of site collections where a specific feature got activated at the site collection level, the below script will be helpful.

For example, to know the list of site collection where the Nintex wokrflow got activated, use the below script.

 
$GC = Start-SPAssignment

$sites=$GC | Get-SPSite -Limit All


foreach($site in $sites)

{

$feature=Get-SPFeature -Site $site | Where-object {$_.DisplayName -eq "NintexWorkflow"}

if($feature -ne $null)
{
  write-host "Feature activated at site" $site.Url

}
$site.dispose()
}

Stop-SPAssignment $GC
 
If you want the spcific publishing feature or custom feature activated site collection list, replace the feature display name with the custom one.