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)
}

$manager.Dispose()
$web.Dispose()
#

Advertisements

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

Solution:
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

 

Tip:

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

Source : http://www.jeremytaylor.net/

 

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
$OpenWeb.Dispose();
$SPSite.Dispose()

Run script Completed ! Enjoy !