Change the Workflow autocleanup retention days in SharePoint Server 2019

Raees K 1 Reputation point
2021-04-05T07:16:44.82+00:00

Dear,

Is there any possible way to change the workflow auto cleanup days from 60 days to 365 days for SharePoint Server 2019. Facing may issues due to the auto cleanup. Kindly help.

Regards,

Microsoft 365 and Office | SharePoint Server | For business
{count} votes

1 answer

Sort by: Most helpful
  1. Jerry Xu-MSFT 7,961 Reputation points
    2021-04-06T02:58:44.347+00:00

    Hi, @Raees K ,

    You can use PowerShell to change the AutoCleanUpDays property of workflow from default 60 days to 365. It is a workflow level property so you can change only the required workflows. And workflows are associated to list, you need to know the list name.

    Here are scripts work in my end:

    For changing a specific workflow:

    $site=get-spweb -site "<siteURL>"  
    $list=$site.lists["<ListName>"]  
    $wfs=$list.WorkflowAssociations  
    $wf=$wfs.GetAssociationByName("<WorkflowName>","en-US")  
    $wf.autocleanupdays=365  
    $wfs.update($wf)  
    

    And if you want to change all the workflow in a list.

    $site=get-spweb -site "<SiteURL>"  
    $list=$site.lists["<ListName>"]  
    $wfs=$list.WorkflowAssociations  
    for ($i = 0; $i -lt $wfs.Count; $i++)  
    {  
    	$wf=$wfs[$i]  
    	$wf.autocleanupdays=365  
    	$wfs.update($wf)  
    }  
    

    Let me know if it works well or not.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.