-
Notifications
You must be signed in to change notification settings - Fork 1
/
SPWorkflowRetention.ps1
44 lines (39 loc) · 1.78 KB
/
SPWorkflowRetention.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#Powershell Playset
#Workflow Retention Update
# Sample Usage
# Set-SPListWorkflowAssocationCleanup -WebUrl "<url>" -ListName "<list name>" -CleanupDays 365 -ReportOnly:$false
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function Set-SPListWorkflowAssocationCleanup {
param (
[string] $WebUrl = $(Read-Host -prompt "Enter a Url"),
[string] $ListName = $(Read-Host -prompt "Enter a List Name"),
[int32] $CleanupDays = $(Read-Host -prompt "Enter the number of Cleanup Days"),
[switch] $ReportOnly = $true
)
$web = Get-SPWeb $WebUrl;
if ($web -eq $null) {
Write-Error -message "Error: Web Not Found" -category InvalidArgument
} else {
$list = $web.Lists[$ListName];
if ($list -eq $null) {
Write-Error -message "Error: List Not Found" -category InvalidArgument
} else {
[Microsoft.SharePoint.Workflow.SPWorkflowAssociation[]] $wfaMods = @();
foreach ($wfa in $list.WorkflowAssociations) {
$message = "Found Workflow Association for " + $wfa.Name + " with AutoCleanupDays set to " + $wfa.AutoCleanupDays
Write-Verbose -message $message -verbose
if ($ReportOnly -eq $false) {
$wfa.AutoCleanupDays = $CleanupDays;
$wfaMods = $wfaMods + $wfa;
}
}
if ($ReportOnly -eq $false) {
foreach ($wfa in $wfaMods) {
$message = "Setting AutoCleanupDays for " + $wfa.Name + " to " + $CleanupDays
Write-Verbose -message $message -verbose
$list.WorkflowAssociations.Update($wfa);
}
}
}
}
}