-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGet-ScriptCopPatrol.ps1
62 lines (58 loc) · 1.98 KB
/
Get-ScriptCopPatrol.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
function Get-ScriptCopPatrol
{
<#
.Synopsis
Gets the currently defined script cop patrols.
.Description
Gets the currently defined script cop patrols.
A Script Cop patrol groups a number of rules to help easily fix a set of issues.
.Example
Get-ScriptCopPatrol
.Link
Register-ScriptCopPatrol
#>
[CmdletBinding(DefaultParameterSetName='All')]
[OutputType([PSObject])]
param(
# The name of the patrol.
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ParameterSetName='Name')]
[string]
$Name
)
begin {
# Declare Control Cache if it Doesn't Exist
if (-not ($script:ScriptCopPatrols)) {
$script:ScriptCopPatrols = @{}
}
}
process {
if ($psCmdlet.parameterSetName -eq 'Name' -and $script:ScriptCopPatrols[$name]) {
#region Create a PSObject to hold the results
$result = New-Object PSObject
$result.psObject.Properties.add(
(New-Object Management.Automation.PSNoteProperty "Name", $Name)
)
$result.psObject.Properties.add(
(New-Object Management.Automation.PSNoteProperty "Description",
$script:ScriptCopPatrols[$name].Description)
)
$result.psObject.Properties.add(
(New-Object Management.Automation.PSNoteProperty "CommandRule",
$script:ScriptCopPatrols[$name].CommandRule)
)
$result.psObject.Properties.add(
(New-Object Management.Automation.PSNoteProperty "ModuleRule",
$script:ScriptCopPatrols[$name].ModuleRule)
)
$result
#endregion
} elseif ($psCmdlet.parameterSetName -eq 'All') {
#region Use Recursion to get the PSObject for each patrol
$script:ScriptCopPatrols.Keys |
Get-ScriptCopPatrol
#endregion
}
}
}