2
2
about_PSScriptAnalyzer
3
3
4
4
SHORT DESCRIPTION
5
- PSScriptAnalyzer is a static code checker for PowerShell modules and scripts .
5
+ PSScriptAnalyzer is a static code checker for PowerShell script .
6
6
7
7
LONG DESCRIPTION
8
- PSScriptAnalyzer checks the quality of Windows PowerShell code by running a
9
- set of rules. The rules are based on PowerShell best practices identified by
8
+ PSScriptAnalyzer checks the quality of Windows PowerShell script by evaluating
9
+ that script against a set of rules. The script can be in the form of a
10
+ stand-alone script (.ps1 files), a module (.psm1, .psd1 and .ps1 files) or
11
+ a DSC Resource (.psm1, .psd1 and .ps1 files).
12
+
13
+ The rules are based on PowerShell best practices identified by the
10
14
PowerShell Team and the community. These rules can help you create more
11
15
readable, maintainable and reliable scripts. PSScriptAnalyzer generates
12
- DiagnosticResults (errors and warnings) to inform users about potential code
13
- defects and suggests possible solutions for improvements.
16
+ DiagnosticResults (errors and warnings) to inform you about potential script
17
+ issues, including the reason why there might be an issue, and provide you
18
+ with guidance on how to fix the issue.
14
19
15
- PSScriptAnalyzer is shipped with a collection of built-in rules that checks
20
+ PSScriptAnalyzer is shipped with a collection of built-in rules that check
16
21
various aspects of PowerShell code such as presence of uninitialized
17
- variables, usage of PSCredential Type, usage of Invoke-Expression etc.
18
- Additional functionalities such as exclude/include specific rules are also
19
- supported.
22
+ variables, usage of the PSCredential Type, usage of Invoke-Expression, etc.
23
+
24
+ The following additional functionality is also supported:
25
+
26
+ * Including and/or excluding specific rules globally
27
+ * Suppression of rules within script
28
+ * Creation of custom rules
29
+ * Creation of loggers
20
30
21
31
RUNNING SCRIPT ANALYZER
22
32
@@ -35,7 +45,7 @@ RUNNING SCRIPT ANALYZER
35
45
36
46
PS C:\> Invoke-ScriptAnalyzer -Path myscript.ps1
37
47
38
- That will analyze your script against every built-in rule. As you may find
48
+ This will analyze your script against every built-in rule. As you may find
39
49
if your script is sufficiently large, that could result in a lot of warnings
40
50
and/or errors. See the next section on recommendations for running against
41
51
an existing script, module or DSC resource.
@@ -106,7 +116,7 @@ RUNNING SCRIPT ANALYZER ON AN EXISTING SCRIPT, MODULE OR DSC RESOURCE
106
116
are likely to generate prodigious amounts of output. While these rules have
107
117
their reason for being many existing scripts violate these rules over and
108
118
over again. It would be a shame if you let a flood of warnings from these two
109
- rules, dissuade you from looking at potentially more serious warnings.
119
+ rules, keep you from addressing more potentially serious warnings.
110
120
111
121
There may be other rules that generate a lot of output that you don't care
112
122
about - at least not yet. As you examine the remaining diagnostics output,
@@ -130,21 +140,21 @@ RUNNING SCRIPT ANALYZER ON AN EXISTING SCRIPT, MODULE OR DSC RESOURCE
130
140
3 PSPossibleIncorrectComparisonWithNull
131
141
1 PSAvoidUsingComputerNameHardcoded
132
142
133
- I may decide to exclude the PSAvoidUsingInvokeExpression rule for the moment
143
+ You may decide to exclude the PSAvoidUsingInvokeExpression rule for the moment
134
144
and focus on the rest, especially the PSUseDeclaredVarsMoreThanAssigments,
135
145
PSAvoidUninitializedVariable and PSPossibleIncorrectComparisonWithNull rules.
136
146
137
147
As you fix rules, go back and enable more rules as you have time to address
138
148
the associated issues. In some cases, you may want to suppress a rule at
139
- the function, script or class scope instead of globally excluding rule. See
140
- the RULE SUPPRESSION section below.
141
-
142
- While getting a completely clean run through every rule is a
143
- noble goal, it may not always be feasible. You have to weigh the gain of
144
- passing the rule and eliminating a "potential" issue with changing script
145
- and possibly introducing a new problem. In the end, for existing scripts,
146
- it is usually best to have evaluated the rule violations that you deem the
147
- most valuable to address.
149
+ the function, script or class scope instead of globally excluding the rule.
150
+ See the RULE SUPPRESSION section below.
151
+
152
+ While getting a completely clean run through every rule is a noble goal, it
153
+ may not always be feasible. You have to weigh the gain of passing the rule
154
+ and eliminating a "potential" issue with changing script and possibly
155
+ introducing a new problem. In the end, for existing scripts, it is usually
156
+ best to have evaluated the rule violations that you deem the most valuable to
157
+ address.
148
158
149
159
RULE SUPPRESSSION
150
160
@@ -198,4 +208,3 @@ SEE ALSO
198
208
Invoke-ScriptAnalyzer
199
209
Set-StrictMode
200
210
about_Pester
201
-
0 commit comments