Get-ScriptAnalyzerRule
Gets the script analyzer rules on the local computer.
구문
Default (기본값)
Get-ScriptAnalyzerRule
[[-Name] <string[]>]
[-CustomRulePath <string[]>]
[-RecurseCustomRulePath]
[-Severity <string[]>]
[<CommonParameters>]
Description
Gets the script analyzer rules on the local computer. You can select rules by Name, Severity, Source, or SourceType, or even particular words in the rule description.
Use this cmdlet to create collections of rules to include and exclude when running the
Invoke-ScriptAnalyzer
cmdlet.
To get information about the rules, see the value of the Description property of each rule.
The PSScriptAnalyzer module tests the PowerShell code in a script, module, or DSC resource to determine if it fulfils best practice standards.
예제
EXAMPLE 1 - Get all Script Analyzer rules on the local computer
Get-ScriptAnalyzerRule
EXAMPLE 2 - Gets only rules with the Error severity
Get-ScriptAnalyzerRule -Severity Error
EXAMPLE 3 - Run only the DSC rules with the Error severity
This example runs only the DSC rules with the Error severity on the files in the MyDSCModule module.
$DSCError = Get-ScriptAnalyzerRule -Severity Error | Where-Object SourceName -eq PSDSC
$Path = "$home\Documents\WindowsPowerShell\Modules\MyDSCModule\*"
Invoke-ScriptAnalyzerRule -Path $Path -IncludeRule $DSCError -Recurse
Using the IncludeRule parameter of Invoke-ScriptAnalyzerRule
is more efficient than using its
Severity parameter, which is applied only after using all rules to analyze all module files.
EXAMPLE 4 - Get rules by name and severity
This example gets rules with "Parameter" or "Alias" in the name that generate an Error or Warning. You can use this set of rules to test the parameters of your script or module.
$TestParameters = Get-ScriptAnalyzerRule -Severity Error, Warning -Name *Parameter*, *Alias*
EXAMPLE 5 - Get custom rules
This example gets the standard rules and the rules in the VeryStrictRules and ExtremelyStrictRules modules. The command uses the RecurseCustomRulePath parameter to get rules defined in subdirectories of the matching paths.
Get-ScriptAnalyzerRule -CustomRulePath $home\Documents\WindowsPowerShell\Modules\*StrictRules -RecurseCustomRulePath
매개 변수
-CustomRulePath
By default, PSScriptAnalyzer gets only the standard rules specified in the
Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
file in the module. Use this
parameter to get the custom Script Analyzer rules in the specified path and the standard Script
Analyzer rules.
Enter the path to a .NET assembly or module that contains Script Analyzer rules. You can enter only one value, but wildcards are supported. To get rules in subdirectories of the path, use the RecurseCustomRulePath parameter.
You can create custom rules using a .NET assembly or a PowerShell module, such as the Community Analyzer Rules in the GitHub repository.
매개 변수 속성
형식: | String[] |
Default value: | None |
와일드카드 지원: | True |
DontShow: | False |
별칭: | CustomizedRulePath |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
-Name
Gets only rules with the specified names or name patterns. Wildcards are supported. If you list multiple names or patterns, it gets all rules that match any of the name patterns.
매개 변수 속성
형식: | String[] |
Default value: | All rules |
와일드카드 지원: | True |
DontShow: | False |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
-RecurseCustomRulePath
Searches the CustomRulePath ___location recursively to add rules defined in files in subdirectories
of the path. By default, Get-ScriptAnalyzerRule
adds only the custom rules in the specified path.
매개 변수 속성
형식: | SwitchParameter |
Default value: | False |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
-Severity
Gets only rules with the specified severity values. Valid values are:
- Information
- Warning
- Error
매개 변수 속성
형식: | String[] |
Default value: | All rules |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
입력
None
You can't pipe input to this cmdlet.
출력
Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.RuleInfo
The RuleInfo object is a custom object created specifically for Script Analyzer.