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.
 
 

Tuesday, September 24, 2013

SharePoint Health Analyser automated mail using Powershell

Hi guys,

Got a requirement to send the farm health report to the farm adminstrators group to get the updates automatically throgh the mail.

After some research, I found the basic power shell script which pulls the data from Health Reports list in the central administration web application

I modified and updated the script to get the severity incidents in the HTML tabular form ,

We can execute the script with task scheduler for automation.

Content Query web part --Querying multiple specific lists

Hi guys,

How to query the data from multiple lists in SharePoint using content query webpart?

 I have a simple requirement to display the latest 5 document links from multiple document libraries in the current site.

 In general, share point out of the box feature provides the way to query the data from a particular list or all the lists/document libraries in a site or entire site collection.

 If you want to query the data from multiple specific lists, you have to do in in the below way.

 Add the content query webpart to the page,by editing the page and it comes in Content Roll up category. Note- if you are not able to see content query webpart in content roll up category, then your site's publishing feature is not activated. Activate that feature at the site collection level and also at the site level [make sure you have site collection administrator rights.]

 In the content query web part tool box section, select the radio button, that shows "select all the lists/document libraries in the site" and do the remaining filter and sort options, presentation things as per your requirement.

 Finally click Apply button ,then save the page and do the export web part.

 Open the .webpart file after you export it, modify the .webpart file in designer and then find the below property "ListsOverride ".

Get the List GUIDs from the list settings page, for which you want to query the lists.

 Modify that tag similar to the below one.