-
Notifications
You must be signed in to change notification settings - Fork 4
/
Test-ScriptCopFixer.ps1
59 lines (48 loc) · 1.83 KB
/
Test-ScriptCopFixer.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
function Test-ScriptCopFixer
{
[CmdletBinding(DefaultParameterSetName='TestCommandInfo')]
param(
[Parameter(ParameterSetName='TestCommandInfo',Mandatory=$true,ValueFromPipeline=$true)]
[Management.Automation.CommandInfo]
$CommandInfo
)
process {
<#
Only 3 types of commands can possibly be ScriptCopFixers:
- FunctionInfo
- CmdletInfo
- ExternalScriptInfo
#>
if ($CommandInfo -isnot [Management.Automation.FunctionInfo] -and
$CommandInfo -isnot [Management.Automation.CmdletInfo] -and
$CommandInfo -isnot [Management.Automation.ExternalScriptInfo]
) {
Write-Error "$CommandInfo is not a function, cmdlet, or script"
return
}
if (-not $commandInfo.Parameters.Rule -and
$commandInfo.Parameters.Rule.ParameterType -ne [PSObject])
{
Write-Error "$CommandInfo is missing the -Rule parameter"
return
}
if (-not $commandInfo.Parameters.ItemWithProblem -and
$commandInfo.Parameters.ItemWithProblem.ParameterType -ne [PSObject])
{
Write-Error "$CommandInfo is missing the -ItemWithProblem parameter"
return
}
if (-not $commandInfo.Parameters.Problem -and
$commandInfo.Parameters.Problem.ParameterType -ne [Management.Automation.ErrorRecord])
{
Write-Error "$CommandInfo is missing the -Problem parameter"
return
}
if (-not $commandInfo.Parameters.NotInteractive -and
$commandInfo.Parameters.NotInteractive.ParameterType -ne [Switch])
{
Write-Error "$CommandInfo is missing the -NonInteractive switch"
return
}
}
}