Invoke-ScriptAnalyzer

Invoke-ScriptAnalyzer

Starts analyzing a specified script by using ScriptAnalyzer.

구문

Parameter Set: Default
Invoke-ScriptAnalyzer [-Path] <String> [-CustomizedRulePath <String[]> ] [-ExcludeRule <String[]> ] [-IncludeRule <String[]> ] [-LoggerPath <String[]> ] [-Recurse] [-Severity <String[]> ] [ <CommonParameters>]

자세한 설명

Invoke-ScriptAnalyzer starts analyzing one or more specified scripts by using ScriptAnalyzer, evaluating your scripts against a set of best practice measures called rules. ScriptAnalyzer works by evaluating scripts against either all available rules, or against a set of rules that you specify by adding the ExcludeRule or IncludeRule parameters. After ScriptAnalyzer finishes evaluating your scripts, it displays results in the console window.

ScriptAnalyzer works on .ps1 and .psm1 files. Although you can run this release of ScriptAnalyzer on DSC resources, the output might not be as helpful; this functionality is not fully available in this release.

Windows PowerShell includes many built-in rules, but ScriptAnalyzer can also use customized rules that you write in Windows PowerShell scripts, or compile in assemblies by using C#. Just as with the built-in rules, you can add the ExcludeRule and IncludeRule parameters to your Invoke-ScriptAnalyzer command to exclude or include custom rules.

Invoke-ScriptAnalyzer lets you specify a customized logger assembly by adding the LoggerPath parameter. A logger is a tool that monitors the progress or output when you are using a cmdlet. A customized logger lets you track elements of cmdlet use that you want to track. The customized logger must be defined by using C#, and compiled as an assembly.

You can also filter results by severity level (Warning, Error, or Strict) by adding the Severity parameter.

매개 변수

-CustomizedRulePath<String[]>

Path to a customized or user-created module or assembly of rules.

별칭

없음

필수 여부

false

위치

named

기본값

없음

파이프라인 입력 허용 여부

false

와일드카드 문자 허용 여부

false

-ExcludeRule<String[]>

Specifies the names of one or more rules that you want ScriptAnalyzer to exclude from the evalution process. Use the value of the Name property when you want to exclude a rule from script analysis. Separate multiple rule names with commas.

별칭

없음

필수 여부

false

위치

named

기본값

없음

파이프라인 입력 허용 여부

false

와일드카드 문자 허용 여부

false

-IncludeRule<String[]>

Specifies the names of one or more rules that you want ScriptAnalyzer to include in the evalution process. When you add the IncludeRule parameter, only the specified rules are applied to the analysis. Use the value of the Name property when you want to include a rule in script analysis. Separate multiple rule names with commas.

별칭

없음

필수 여부

false

위치

named

기본값

없음

파이프라인 입력 허용 여부

false

와일드카드 문자 허용 여부

false

-LoggerPath<String[]>

Specifies one or more paths to customized logger assemblies. Separate multiple paths with commas.

별칭

없음

필수 여부

false

위치

named

기본값

없음

파이프라인 입력 허용 여부

false

와일드카드 문자 허용 여부

false

-Path<String>

Specifies a path to a script file that you want to analyze, or to a folder that contains multiple scripts that you want to analyze.

별칭

PSPath

필수 여부

true

위치

1

기본값

없음

파이프라인 입력 허용 여부

false

와일드카드 문자 허용 여부

false

-Recurse

Applies rules to script files in the specified path, and in all subfolders.

별칭

없음

필수 여부

false

위치

named

기본값

none

파이프라인 입력 허용 여부

false

와일드카드 문자 허용 여부

false

-Severity<String[]>

If you add this parameter, the DiagnosticRecord displays only results that match the specified severity levels. Valid values for this parameter are Warning, Error, and Strict. Separate multiple severity levels with commas.

별칭

없음

필수 여부

false

위치

named

기본값

없음

파이프라인 입력 허용 여부

false

와일드카드 문자 허용 여부

false

<CommonParameters>

이 cmdlet은 -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, -OutVariable 등의 일반 매개 변수를 지원합니다. 자세한 내용은 TechNet의 about_CommonParameters(https://go.microsoft.com/fwlink/p/?LinkID=113216)

입력

입력 형식은 cmdlet으로 파이프할 수 있는 개체의 형식입니다.

출력

출력 형식은 cmdlet 실행 시 출력되는 개체의 형식입니다.

  • Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord

-------------------------- EXAMPLE 1 --------------------------

This example runs ScriptAnalyzer on one script, Test-Script.ps1. The command applies all default (built-in) rules on script files in the specified path.

PS C:\>Invoke-ScriptAnalyzer -Path D:\test_scripts\Test-Script.ps1

-------------------------- EXAMPLE 2 --------------------------

This example runs ScriptAnalyzer on all scripts that are stored in the folder D:\test_scripts.

PS C:\>Invoke-ScriptAnalyzer -Path D:\test_scripts

-------------------------- EXAMPLE 3 --------------------------

This example adds the Recurse parameter to analyze script files in the directory specified by the Path parameter, and in all of its subfolders.

PS C:\>Invoke-ScriptAnalyzer -Path d:\test_scripts -Recurse

-------------------------- EXAMPLE 4 --------------------------

This example runs ScriptAnalyzer on the Test-Script.ps1 script, and instructs ScriptAnalyzer to include only the built-in rule, PSAvoidUsingCmdletAliases, in its analysis.

PS C:\>Invoke-ScriptAnalyzer -Path C:\users\test\Documents\demo\Test-Script.ps1 -IncludeRule "PSAvoidUsingCmdletAliases"

-------------------------- EXAMPLE 5 --------------------------

This example runs ScriptAnalyzer on the Test-Script.ps1 script, and instructs ScriptAnalyzer to exclude the built-in rules, PSAvoidUsingCmdletAliases and PSAvoidUsingInternalURLs, from its analysis.

PS C:\>Invoke-ScriptAnalyzer -Path d:\test_scripts\Test-Script.ps1 -ExcludeRule "PSAvoidUsingCmdletAliases","PSAvoidUsingInternalURLs"

-------------------------- EXAMPLE 6 --------------------------

This example runs ScriptAnalyzer on the Test-Script.ps1 script, and instructs ScriptAnalyzer to show only those results with a severity level of Warning.

PS C:\>Invoke-ScriptAnalyzer -Path D:\test_scripts\Test-Script.ps1 -Severity "Warning"

-------------------------- EXAMPLE 7 --------------------------

This example runs ScriptAnalyzer on the Test-Script.ps1 script, but adds the CustomizedRulePath parameter to instruct ScriptAnalyzer to evaluate the script against user-created rules in C:\CommunityAnalyzerRules.

PS C:\>Invoke-ScriptAnalyzer -Path d:\test_scripts\test.ps1 Invoke-ScriptAnalyzer -Path D:\test_scripts\Test-Script.ps1 -CustomizedRulePath C:\CommunityAnalyzerRules

관련 항목

Get-ScriptAnalyzerRule