Start a specific Workflow on all items in a List via Powershell

# URL of the Site
$web = Get-SPWeb -Identity “http://knowledgebase”

$manager = $web.Site.WorkFlowManager

# Name of the list
$list = $web.Lists[“knowledgebase”]

# Name of the Workflow
$assoc = $list.WorkflowAssociations.GetAssociationByName(“Update Author”,”en-GB”)

$data = $assoc.AssociationData
$items = $list.Items
foreach($item in $items)
$wf = $manager.StartWorkFlow($item,$assoc,$data,$true)



The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator

You get this error, when trying to run a workflow manually via the FE or when using InfoPath Forms

You would need to install the ‘State Service’ via the Configuration wizard in Central Administration or via PowerShell.

To configure the State Service by using Windows PowerShell:
1. Click Start, Administrative Tools, Windows PowerShell Modules.
2. In Windows PowerShell, type $serviceApp = New-SPStateServiceApplication -Name “State Service”
3. Create a State Service database and associate it with a service application, by typing New-SPStateServiceDatabase -Name “StateServiceDatabase” -ServiceApplication $serviceApp
4. Create a State Service Application Proxy and associate it with the service application by typing New-SPStateServiceApplicationProxy -Name “State Service” -ServiceApplication $serviceApp -DefaultProxyGroup
(You can use another proxy group if necessary by changing the DefaultProxyGroup parameter)

PS Code :

$serviceApp = New-SPStateServiceApplication -Name “State Service”
New-SPStateServiceDatabase -Name “StateServiceDatabase” -ServiceApplication $serviceApp
New-SPStateServiceApplicationProxy -Name “State Service” -ServiceApplication $serviceApp -DefaultProxyGroup



You can view a list of all State Service cmdlets in Windows PowerShell by typing gcm *spstate*

Source :


How to Create Fields to SharePoint List using PowerShell

$SPSite = New-Object Microsoft.SharePoint.SPSite(“http://intranet”);
#Open you web
$OpenWeb = $SpSite.OpenWeb();
#Open Your List
$List = $OpenWeb.Lists[“eMedication”];
#Add User Field to list
$List.Fields.Add(“UserField”, “User”, $User)
#Add TextField to list
$List.Fields.Add(“TextField”, “Text”, $Text)
#Add UrlHyperField Field to list

Run script Completed ! Enjoy ! 

Customizing DateTime format on a List view Web part

SharePoint does not allow you to format the output in a list view web part. Here is a little trick on how to fix that.

  • Create a new calculated column for your list (single line of text)
  • Use the following formula to calculate its value


=TEXT([Column Name],”dd mmm yy”) – To Display the Date Only

=TEXT([Column Name],”hh mm”) – To Display the Time Only


Find SharePoint GUIDs using PowerShell

2007 version:

$site = New-Object Microsoft.SharePoint.SPSite("http://yourserver/sites/yoursite")
$web = $site.OpenWeb("yoursubsite")
write-host "Site: " + $
write-host "Web: " + $
$web.lists | Format-Table title,id -AutoSize


2010 version:

$site = Get-SPSite http://yourserver/sites/yoursite
$web = $site.OpenWeb("yoursubsite")
write-host "Site: " + $
write-host "Web: " + $
$web.lists | Format-Table title,id -AutoSize

Migrate a list from SharePoint 2007 to SharePoint 2010

This is not the best practice method, but works well for most lists..
The first thing I did was save a list as a template in V3 and download to my local machine.
I then renamed the file from *.stp to *.cab and extracted the file Manifest.xml
The first change to make to manifest is to change

<productversion>3</productversion> to

Simple enough.
The next change I made was for any lookup fields I had.
Do a search in the file for your lookup fields.
You will see an attribute on the that looks like List=”{GUID}”.

All you have to do is change the attribute to List=”Lists/<List name>” where < List name> is the name of the lookup list. And that is it.

Create a new CAB file, add your manifest and rename the file to *.stp again.

Upload the template to the SharePoint 2010 templates gallery.

Make sure that all source lookup lists have been created and then create your new list from the template.

When I did this I even had it keep the data in the template and everything matched up perfectly.

Sharing One List / Library across multiple sub-sites.

I wanted to create a Master Contact List on the main site & add a webpart to Show Filtered departmental contacts on various department subsites.

The problem I ran into was that I wasn’t able to add list from the main site to any of the subsites.

I spend a few days looking at the issue & realised that I had to export the web-part; but SP2010 doesn’t allow this for List & Libraries.

Googling around a bit I found a post on Mike Smith’s blog with help me resolve the issue.

I have modified it slightly to show the steps I took to get around the problem.

Article summary:

  • I will show how to create a custom web part that represents a list or library’s view and use this web part in other sites (at least in the same site collection) without copying documents between sites.
  • This custom web part supports a tool bar so files can be uploaded and maintained in a single library, but viewed and maintained from any site in the site collection that has this web part.
  • Tools needed:
    • SharePoint Designer (to make one quick change, export the web part, and then optionally roll back the change)
    • Some way to find the site’s GUID (tool available on codeplex – called SharePoint Manager)  link below.

The Question:

What started out as a simple question has led to some interesting results. So interesting that someone somewhere else must have written this up. I’ve not found it, so here goes…

The question that started this was “why don’t list and library web parts have a ‘Export’ option?” Most other web parts do.

First some observations:

  • While editing a web part page, click a web part’s menu and you will usually see an Export option, except for list and library web parts.
  • List and library view pages are web part pages (they have “Edit Page” in the Site Actions menu”) and the displayed list is a web part.

So how can you export a list web part?

Turns out to be pretty easy. Edit the page in SharePoint Designer and change one word.

  1. Create a new web-part page on the main site (eg. WPPage.aspx) and add a webpart with the Library / List you wish to export.
  2. Open the site in SharePoint Designer and double click the page with the web part that you have created (WPPage.aspx in my case)
  3. In the code view find the web part and find
    and change from “false” to “true”
  4. Save the page (this will “unghost” the page, but you can undo the changes after the export is complete – right-click the file in the Folder List and select Reset to Site Definition)
  5. Go to a browser and visit this page. Go to Site Actions, Edit Page.
  6. Click Edit in web part you just modified and click Export.
  7. Save the file to a location on your local machine
  8. Give the file a name and save it somewhere where you can find it in the next step.

To import the exported settings as a new web part:

  1. Visit your top level site in the site collection and go to Site Actions, Site Settings, and in the Galleries column click Web Parts

To add the web part.

  1. Nothing special here. Add this web part just like any other web part.

Some differences…

Oddly, the displayed columns are different. The AllItems view displayed Type, Name, Modified and Modified By. The new web part displays Type, Name and Modified By. This is easy to fix. Edit the web part and change the Selected View property to All Documents then you will get the same list of columns in both displays.

The new web part does not display a toolbar by default, but this can be enabled from the web part’s properties panel. If the toolbar is enabled you will see all of the buttons found in the AllItems page, New, Upload, Actions and Settings (depending on the current user’s security rights).

Now test the web part in a sub site….


   Unable to add selected web part(s).
List does not exist.
The page you selected contains a list that does not exist.

On the first attempt it appears that the new exported web part will not work on another site. Time for more research…

Find the missing GUID

Open the .DWP (.WEBPART in 2010) file created by the Export. Find these two lines:

SP 2007 
   <ListName …..>{ list_guid_here } </ListName> 
   <WebId ….> all_zeros_guid_here </WebId>

SP 2010

   <property name=”ListName” type=”string”>{ list_guid_here } </property> 
   <property name=”WebId” …>all_zeros_guid_here </property>

SharePoint uses Globally Unique IDs (GUIDS) to identify just about everything stored in the databases. Notice that the ListName has a GUID, but the WebId is all zeros. Replace the zeros with the GUID for the site that owns the list and all will then work.

How to find a GUID

Download a tool from CodePlex

You will need to point to the parent site & check the ID field. (I shall post one detailing this step too at some point)

Update the web part file

Edit the WebId element and replace the all zeros GUID with the site’s GUID:

SP 2007”   <WebId ….> all_zeros_guid_here </WebId>

SP 2010    <property name=”WebId” …>all_zeros_guid_here </property>

After updating the DWP file with the site’s (web’s) GUID, re-upload it to the web part gallery and go and test the web part in a sub site.
And for the “Strange Things” list… the GUID for the web site does not include brackets ( { } ) and is in lower case. The GUID for the list must have brackets and MUST be in UPPER CASE or it will not work.

Watch outs and warnings!

  • This has not been tested in a production environment – you are on your own! (Please let me know if it works or does not work for you)
  • So far I have only tested this on MOSS 2007 Enterprise and SharePoint Server 2010, but it should work in WSS and SharePoint Foundation.
  • I have tested this so far with document libraries and several lists such as Announcements, but not with every list and library.
  • This will only work within the same site, or within the same site collection. It will not work between site collections, between applications or between servers.
  • The view displayed in the web part is a copy of the view in the original list or library. Use Edit, Modify Shared Web Part to pick another view or to refresh the view.
  • Users will need rights to the original list or library. This web part is only a view of the real list.
  • Alerts will be stored in the site with the original list so alert management will need to be done from that site’s Site Actions, Site Settings menu.
  • Most menu options will display screens from the site with the original list, but when the user clicks OK, Cancel, Close, etc, they will return to the site with the web part. One exception is if an operation generates as error, the “Go back to site” link will take them to the list’s site, not the web part’s site.