3

hi guys i need a help to get easy way to delete work flow from sub site level . its a pain to load it to SPD and do for there since site have lot of work flows .

this Poweshell i got the work flow details .

$site = Get-SPSite "SITEURL"; $site.AllWebs | foreach { $.Lists | foreach { $.WorkflowAssociations | foreach { write-host "Site:" $.ParentWeb.Url ", List:" $.ParentList.Title ", Workflow:" $_.Name } } }

any help is welcome.

Cheers

4

To remove all Workflow Associations in a Site Collection you can do something like:

(Get-SPSite http://sp2010).AllWebs |
  Foreach-Object {
    $wfas = ($_.Lists |
             Select-Object -Expand WorkFlowAssociations | 
             Select-Object Id, ParentList);
    $wfas |
      Foreach-Object {
        if ($_ -ne $null) {
          $_.ParentList.WorkflowAssociations.Remove($_.Id)
        }
      }
  }
0
To delete the Specific Workflow 

  param(  [string] $env = $(Read-Host  -prompt “Specify the environment you want to run on (D-Dev, T-Test,
  P-Production) :”)

)
 $env = $env.ToLower()
 if($env -ne ‘d’ -and $env -ne ‘t’ -and $env -ne ‘p’)
{
    Write-Host “ERROR:  Invalid Input.”
}
else {
               $siteAddress =  $null
     if($env -eq ‘t’)
 {  $siteAddress = ‘http://test.yoursite.com/’ }

    elseif($env -eq ‘d’) 
{
  $siteAddress = ‘http://dev.yoursite.com/’ }
                elseif($env -eq  ‘p’) { $siteAddress = ‘http://yoursite.com/’ }   

  # Get the SPSite object for a  given SharePoint Url

  $SPSite = Get-SPSite
  $siteAddress

  if($SPSite -ne $null)

  {
         # Get the root  website

    $Web = $SPSite.OpenWeb();
     # Get the list  to which we wanted to associate the workflow
       $SPList  =$Web.Lists[“Announcements”];
                 $workflowAssociation  = $SPList.WorkflowAssociations.GetAssociationByName(“SharePoint Approval
  Workflow”, [System.Threading.Thread]::CurrentThread.CurrentCulture);
                 if($workflowAssociation  -ne $null)
                {
                                #  Remove workflow association to list
                                $SPList.RemoveWorkflowAssociation($workflowAssociation);
                                $SPList.Update();
                                Write-Host  “Workflow association removed Successfully.” -foreground color  “Green”
                }
                else
                {
                                Write-Host  “Workflow association could not be found.” -foregroundcolor  “Yellow”
                }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.