-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search-All2010SPWorkflowsforGroups.ps1
104 lines (94 loc) · 3.07 KB
/
Search-All2010SPWorkflowsforGroups.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$csv = import-csv -Path "E:\GroupsforWorkflows.csv"
$groupsinworkflow = @()
$errors = @()
Function GetXOMLFromWorkflowInstance($wfa)
{
clv xmlstring
$name = $wfa.Name
$wfName = $name.Replace(" ", "%20")
$webRelativeFolder = "Workflows1/" + $wfName
$xomlFileName = $wfName + ".xoml"
$wfFolder = $wfa.ParentWeb.GetFolder($webRelativeFolder)
$xomlFile = $wfFolder.Files[$xomlFileName]
if ($xomlFile.Exists)
{
try
{$xomlbin = $xomlFile.OpenBinary()
$encode = New-Object System.Text.ASCIIEncoding
$xmlstring = $encode.GetString($xomlbin)
return $xmlstring
}
catch
{Write-Host "Error $($wfa.name) $($wfa.ParentList) $($wfa.ParentWeb)" -ForegroundColor Red
$props = [ordered]@{
Workflow = $wfa.name;
Parentweb = $wfa.ParentWeb;
Parentlist = $wfa.ParentList;
Author = $wfa.author
}
}
$global:errors += New-object -TypeName psobject -Property $props
}
else {
$webRelativeFolder = "Workflows1/" + $wfName
$xomlFileName = $wfName + ".xoml"
$wfFolder = $wfa.ParentWeb.GetFolder($webRelativeFolder)
try {
$xomlFile = $wfFolder.Files[$xomlFileName]
$xomlbin = $xomlFile.OpenBinary()
$encode = New-Object System.Text.ASCIIEncoding
$xmlstring = $encode.GetString($xomlbin)
}
catch
{Write-Host "Error $($wfa.name) $($wfa.ParentList) $($wfa.ParentWeb)" -ForegroundColor Red
$props = [ordered]@{
Workflow = $wfa.name;
Parentweb = $wfa.ParentWeb;
Parentlist = $wfa.ParentList;
Author = $wfa.author
}
}
$global:errors += New-object -TypeName psobject -Property $props
}
return $xmlstring
}
#return $xomlFileName
Function CheckAllWFXoml ($webUrl, $listName)
{
if ($xml){clv xml}
#$site = Get-SPSite($webUrl)
$web = get-spweb $weburl
$wfaColl = $web.lists[$listname].WorkflowAssociations | ? {$_.name -notlike "*Previous*"}
Foreach ($i in $wfaColl)
{
$xml = GetXOMLFromWorkflowInstance $i
#$xml
foreach ($group in $csv.groups)
{
"Checking $($group) $($web.title) $($list.title) $($i.name)"
if (Select-String -SimpleMatch "$($group)" -InputObject $xml -Quiet)
{
write-host "Found $($group) in $($i.name)" -ForegroundColor Green
$wfprops = [ordered]@{
Group = $group;
WFName = $i.name;
List = $i.parentlist;
Web = $i.parentweb
}
$global:groupsinworkflow +=New-Object -TypeName psobject -Property $wfprops
}
}
}
}
$webs = (get-spsite https://sharepoint.domain.local).allwebs
foreach ($web in $webs)
{
"WEB: $($web.title)"
$lists = $web.lists | ? {$_.workflowassociations}
foreach ($list in $lists)
{
"LIST: $($list.title)"
CheckAllWFXoml $web.url $list.title
}
}