Wednesday, February 15, 2012

PropertyAssignmentException when trying to set workflow association set_Enabled using powershell in SP2010

Sharepoint 2010 & powershell
I am trying to go through all running instances of a workflow and set the association to "No New Instances".  So i found two resources where i combined and made my own script from pieces of both.  i ran into an issue throwing an error
cannot set the value property for psmemberinfo object of type system.management.automation.psmethod"
FullyQualifiedErrorId : PropertyAssignmentException

Write-Host 'Loading SP Commands'
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

$WfName = "SiteApprovalWorkflow"

$url = "http://mySRV/sites/theSite"

$spSite = new-object Microsoft.SharePoint.SPSite($url)

$spWeb = $spSite.OpenWeb()
$workflowBase = $spweb.WorkflowTemplates | where {$_.Name -eq $WfName}

$spWeb.Dispose()

foreach($spWeb in $spSite.AllWebs)
{
    for($i = 0; $i -lt $spWeb.Lists.Count; $i++)
    {
        $spList = $spweb.Lists[$i]
        $assoc = $spList.WorkflowAssociations | where {$_.BaseId -eq $workflowBase.Id.ToString() -and $_.RunningInstances -gt 0}
       
        if($assoc -ne $null)
        {
            $assoc.set_Enabled($false)
            $list.UpdateWorkflowAssociation($assoc)
        }
    }
   
    $spWeb.Dispose()
}
$spSite.Dispose()

 Any ideas what the issue is?

1 comment:

tiger00555 said...

all articles showed the property as set_Enabled when the property is actually Enabled. that did the trick