-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathList-All-Workflows.ps1
88 lines (79 loc) · 2.61 KB
/
List-All-Workflows.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Source: https://blogs.msdn.microsoft.com/vijay/2009/10/01/how-to-list-all-the-sub-sites-and-the-site-collections-within-a-sharepoint-web-application-using-windows-powershell/
param ([boolean] $writeToFile = $true)
#Get List of all workflows in farm with specified custom workflow activity
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#If boolean is set to true, you can specify an outputlocation, to save to textfile.
if($writeToFile -eq $true)
{
$outputPath = Read-Host "Outputpath (e.g. C:\directory\filename.txt)"
}
#Counter variables
$webcount = 0
$listcount = 0
$associationcount = 0
#Get all webs
Get-SPSite -Limit All | % {$webs += $_.Allwebs}
if($webs.count -ge 1)
{
#Iterate through all webs
foreach($web in $webs)
{
#Grab all lists in the current web
$lists = $web.Lists
foreach($list in $lists)
{
foreach($wf in $list.WorkflowAssociations)
{
#Ignore previous versions - Check for other languages too
if($wf.Name -like "*Previous*")
{continue}
#Read Workflow instance XOML file
write-host "`Iterating workflows: " $wf.Name -ForegroundColor "Yellow"
[xml]$xmldocument = $wf.SoapXml
if($xmldocument.FirstChild -ne $null)
{
$name = $xmldocument.FirstChild.GetAttribute("Name")
$wfName = $name.Replace(" ", "%20")
$webRelativeFolder = "Workflows/" + $wfName
$xomlFileName = $wfName + ".xoml"
$wfFolder = $wf.ParentWeb.GetFolder($webRelativeFolder)
$xomlFile = $wfFolder.Files[$xomlFileName]
if ($xomlFile.Exists)
{
$xomlStream = $xomlFile.OpenBinaryStream()
$xmldocument.Load($xomlStream)
$xomlStream.Close()
Write-Host $wf.Name
#Write below custom action dll reference
if($xmldocument.OuterXml -like "*CustomDLLName*")
{
Add-Content -Path $outputPath -Value "$($web.url)+$($list.title)+$($wf.Name)+Custom"
}
else
{
Add-Content -Path $outputPath -Value "$($web.url)+$($list.title)+$($wf.Name)+OOB/Designer"
}
}
else
{
Add-Content -Path $outputPath -Value "$($web.url)+$($list.title)+$($wf.Name)+OOB/Designer"
}
}
else
{
Add-Content -Path $outputPath -Value "$($web.url)+$($list.title)+$($wf.Name)+OOB/Designer"
}
}
}
$webcount +=1
$web.Dispose()
}
#Show total counter for checked webs & lists
Write-Host "Amount of webs checked:"$webcount
$webcount = "0"
}
else
{
Write-Host "No webs retrieved" -ForegroundColor Red -BackgroundColor Black
$webcount = "0"
}