PowerShell SharePoint Error – local farm not available

If you get the one of the following errors when using PowerShell with SharePoint 2010:

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.


Microsoft SharePoint is not supported with version 4.0.30319.17929 of the Microsoft .Net Runtime.

The probable cause is the installation of .NET 4.5, to get around the issue type “PowerShell –v 2” without quotes before running your command.

You may also want to change the Target field value for the SharePoint Management Shell:

1.Click Start, and then right-click SharePoint 2010 Management Shell.

2.Click Properties.

3.Click the Shortcut tab in the SharePoint 2010 Management Shell Properties window.

4.Input the following value in the Target field:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 2.0 -NoExit ” & ‘ C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ‘ ”

View the kb article: http://support.microsoft.com/kb/2796733


Trimming the Workflow History List

If you are running workflows in your SharePoint environment ensure you are maintaining the Workflow History list (this is a hidden list but can be accessed through the url http://sitename/lists/workflow history/). The Workflow Auto Cleanup only removes the associations it does not clean up the entries in the Workflow History list. If the list has grown beyond the recommended maximum (50,000) size it will be almost impossible to manage through the UI, you will need to use PowerShell and download a tool from MSDN to trim the list.

PowerShell: get the number of items from the list

#Check if the SharePoint add-in exist, if not go ahead and add it

if ((Get-PSSnapin
SilentlyContinue) -eq






$spweb.Lists[“Workflow History”]








Cleanup Workflow History tool: http://code.msdn.microsoft.com/CleanWorkflowHistory

The tool does not determine if the Workflow is active or complete before it deletes the item, ensure that you set a time range that takes this into account.

SharePoint Calendar View: Overlays Fail After Import


I was migrating a solution from a source environment to a target environment and came across an issue where a calendar list’s overlay returned errors in the new environment.  I used powershell to export the web from one environment and imported it into the new environment (powershell export-spweb and import-spweb)

When I visited the calendar view in the target environment, here’s the error appeared above the calendar view that the overlay had been applied to.

The Web application at http://SourceServerDNS/Site/Lists/CalendarList/calendar.aspx 
could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application. (00000000-0000-0000-0000-000000000000)

Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.


If you try to navigate into Calendar Overlays that have been applied to the view, you’ll probably be able to see the overlay you created, but when you try to edit it, you’ll find a file not found error.

Click Here for a link to blog that shows a C# solution to the problem

However, I was looking for a codeless solution to the problem.  The rest of this post describes how you can use SharePoint Manager (free on CodePlex) to solve this problem.

  • Download the application from CodePlex and move it onto one of the servers in your SharePoint farm
  • Navigate into your list using the tree view on the left:
    • Web Applications > [Your Web Application] > All Webs > [Your Site] > Lists > [Your Calendar List] > Views > [Your Broken Calendar View]
  •  After you’ve selected your view, in the properties pane on the left, delete the contents of the CalendarSettings property and re-add the overlay manually.
  • OR
  • After you’ve selected your view, in the properties pane on the left, edit the contents of the CalendarSettings property:
    •  Find the <AggregationCalendar><Settings> node and update the WebUrl, ListId and ViewId attributes t reflect the new environment
IMPORTANT: Use SharePoint Manager’s Save button to commit your changes to the CalendarSettings property in the list’s schema.

SharePoint Manager

Filter a SharePoint Chart Web Part by Date Range


SharePoint 2010 offers the Chart Web Part.  It has its place for charting and graphing simple data from:

  • Another Web Part on the page
  • SharePoint Lists
  • Excel Services
  • the Business Data Catalog

You can imagine that the requirement to filter the data you’re charting is a common.  Step 3 of the Web Part’s Data Connection Wizard offers the ability to Retrieve and Filter Data.  However, this filtering does not accommodate all type of filtering that you might expect or require for your chart building tasks.

This solution assumes you’re filtering SharePoint list data.

The Issue

The filtering functionality offered by this web part is not deep.  It allows users to perform exact match filtering.  If you’ve worked with SharePoint views, you’re used to having the ability to use a variety of filter operators in your queries. 

The gap comes when you need to filter data that isn’t an exact match, where you’re using a contains, less than or greater than type conditions.


The Chart Web Part supports exact match type filtering.  We can use a calculated field to create a column that indicates whether the list item should be included in the chart’s data or not. 

This scenario demonstrates how to filter based on a list’s date column, to only include items where the date (Birthday in this case) is greater than a specific year. 

The List Data

SharePoint List Data

Step 1: Create a Calculated Field

You can create a calculated field that returns whether or not the date column on that list item is greater than the specified year.

You can see in the List Data Image, that the calculated field BirthdayYear returns a Boolean indicating whether or not the Birth Year is greater than 2005.

Create a Calculated Field

Step 2: Filter the Data

Now that we have a calculated field to filter the data with, on Step 3 of the wizard (Retrieve and Filter Data), we can add the following filter:

  • Parameter Name: BirthdayYear
  • Type: String
  • Default Value: 1

 Chart Werb Part: Filter the List's Data

The results will appear filtered based on the calculated field’s value:Chart Web Part

Query Lookup Fields with Additional Fields in SharePoint using the CSOM / ECMA / JavaScript

SharePoint’s lookup fields allow you to easily connect lists.  This can be extremely valuable when designing solutions that relate / connect information.

Follow these tips if you are attempting to return the value of one of the Additional Fields from the list that your lookup value came from.

Reference the Field’s Internal Name

You’ll notice that that the notation for the additional field is: originalLookupColumn:AdditionalField.  Wherever you reference the lookup field’s additional column, you must use the field’s internal name.  You should be able to replace the colon above with _x003a_ in this example, the internal field name would be: originalLookupColumn_x003a_AdditionalField.

_x003a_ < In case the blog’s font is unreadable, those are the number zero, not the letter ‘o’.

Is the Field Selected?

  • In your CAML, double check that the <viewfields> element contans a <fieldref> element that declares your the lookup value’s additional field


  • In your ClientContext.Load Includes statement, reference the lookup field’s additional field


  • Don’t attemp to reduce the list of fields AT ALL, and return all columns.

Get the Item’s Value

After you’re successfully queried the list, you’ll need to use the get_lookupvalue to return the value of the lookup field’s additional value.

var itemValue = spItem.get_item(‘originalLookupColumn_x003a_AdditionalField).get_lookupValue();

Move a SharePoint Document / SPFile across Farms using an HTTP PUT

If you have reference to a SPFile, here’s a quick method of using the System.Net.WebClient to push the file into another SharePoint farm.

  1. We’re using for a scenario in which documents need to be pushed from an Intranet envrionment to an Extranet environment or from one farm into another.
  2. I’ve hard coded the credentials in this example.  In the Intranet Farm to Extranet Farm scenario, the domains or users may not be the same, so a service account or other credentials may be necessary.
    1. You could use CredentialCache.DefaultCredentials if you’re sure the credentials will work from source to target.  If not, you’ll receive a 401 Error on the WebClient.UploadData method.

Here’s the sample C#

        internal static void moveDocumentToExtranet(string fullTargetPath, SPFile spf)
            WebClient webClient = new WebClient();
            webClient.Credentials = new NetworkCredential("<<UserName>>", "<<Password>>", "<<Domain>>");
            webClient.UploadData(fullTargetPath, "PUT", spf.OpenBinary());                       

Passing extra Parameters into your Callback functions in SharePoint ECMA / JavaScript

When you’re executing a SharePoint client API call asynchronously, being able to pass an extra parameter into the success callback function can come in extremely handy. 

Click Here for the MSDN docs for creating executing the currently pending request asynchronously

SP.ClientRuntimeContext.executeQueryAsync(succeededCallback, failedCallback);

Kiran Gadekar wrote a great post on one method of taking care of this that I wanted to share: