11---
22external help file : Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml
33Module Name : PSScriptAnalyzer
4- ms.date : 10/ 07/2021
4+ ms.date : 07/23/2026
55online version : https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-scriptanalyzer?view=ps-modules&wt.mc_id=ps-gethelp
66schema : 2.0.0
77---
@@ -107,7 +107,12 @@ This example runs all rules except for **PSAvoidUsingCmdletAliases** and
107107subdirectories.
108108
109109``` powershell
110- Invoke-ScriptAnalyzer -Path C:\ps-test\MyModule -Recurse -ExcludeRule PSAvoidUsingCmdletAliases, PSAvoidUsingInternalURLs
110+ $invokeScriptAnalyzerSplat = @{
111+ Path = 'C:\ps-test\MyModule'
112+ Recurse = $true
113+ ExcludeRule = 'PSAvoidUsingCmdletAliases', 'PSAvoidUsingInternalURLs'
114+ }
115+ Invoke-ScriptAnalyzer @invokeScriptAnalyzerSplat
111116```
112117
113118### EXAMPLE 5 - Run Script Analyzer with custom rules
@@ -116,13 +121,19 @@ This example runs Script Analyzer on `Test-Script.ps1` with the standard rules a
116121` C:\CommunityAnalyzerRules ` path.
117122
118123``` powershell
119- Invoke-ScriptAnalyzer -Path D:\test_scripts\Test-Script.ps1 -CustomRulePath C:\CommunityAnalyzerRules -IncludeDefaultRules
124+ $invokeScriptAnalyzerSplat = @{
125+ Path = 'D:\test_scripts\Test-Script.ps1'
126+ CustomRulePath = 'C:\CommunityAnalyzerRules'
127+ IncludeDefaultRules = $true
128+ }
129+ Invoke-ScriptAnalyzer @invokeScriptAnalyzerSplat
120130```
121131
122132### EXAMPLE 6 - Run only the rules that are Error severity and have the PSDSC source name
123133
124134``` powershell
125- $DSCError = Get-ScriptAnalyzerRule -Severity Error | Where SourceName -eq PSDSC
135+ $DSCError = Get-ScriptAnalyzerRule -Severity Error |
136+ Where-Object SourceName -eq PSDSC
126137$Path = "$home\Documents\WindowsPowerShell\Modules\MyDSCModule"
127138Invoke-ScriptAnalyzerRule -Path $Path -IncludeRule $DSCError -Recurse
128139```
@@ -145,34 +156,32 @@ function Get-Widgets
145156{
146157 [CmdletBinding()]
147158 [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")]
148- [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingCmdletAliases", "", Justification="Resolution in progress.")]
159+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingCmdletAliases", "",
160+ Justification="Resolution in progress.")]
149161 Param()
150162
151- dir $pshome
163+ dir $PSHOME
152164 ...
153165}
154166
155167Invoke-ScriptAnalyzer -Path .\Get-Widgets.ps1
156168```
157169
158170``` Output
159- RuleName Severity FileName Line Message
160- -------- -------- -------- ---- -------
161- PSProvideCommentHelp Information ManageProf 14 The cmdlet 'Get-Widget' does not have a help comment.
162- iles.psm1
171+ RuleName Severity FileName Line Message
172+ -------- -------- -------- ---- -------
173+ PSProvideCommentHelp Information ManageProfiles.psm1 14 The cmdlet 'Get-Widget' does not have a help comment.
163174```
164175
165176``` powershell
166177Invoke-ScriptAnalyzer -Path .\Get-Widgets.ps1 -SuppressedOnly
167178```
168179
169180``` Output
170- Rule Name Severity File Name Line Justification
171- --------- -------- --------- ---- -------------
172- PSAvoidUsingCmdletAliases Warning ManageProf 21 Resolution in progress.
173- iles.psm1
174- PSUseSingularNouns Warning ManageProf 14
175- iles.psm1
181+ Rule Name Severity File Name Line Justification
182+ --------- -------- --------- ---- -------------
183+ PSAvoidUsingCmdletAliases Warning ManageProfiles.psm1 21 Resolution in progress.
184+ PSUseSingularNouns Warning ManageProfiles.psm1 14
176185```
177186
178187The second command uses the ** SuppressedOnly** parameter to report violations of the rules that are
@@ -192,7 +201,7 @@ value of the **Profile** parameter is the path to the Script Analyzer profile.
192201 ExcludeRules = '*WriteHost'
193202}
194203
195- Invoke-ScriptAnalyzer -Path $pshome \Modules\BitLocker -Settings .\ScriptAnalyzerProfile.txt
204+ Invoke-ScriptAnalyzer -Path $PSHOME \Modules\BitLocker -Settings .\ScriptAnalyzerProfile.txt
196205```
197206
198207If you include a conflicting parameter in the ` Invoke-ScriptAnalyzer ` command, such as
@@ -208,15 +217,16 @@ Invoke-ScriptAnalyzer -ScriptDefinition "function Get-Widgets {Write-Host 'Hello
208217```
209218
210219``` Output
211- RuleName Severity FileName Line Message
212- -------- -------- -------- ---- -------
213- PSAvoidUsingWriteHost Warning 1 Script
214- because
215- there i
216- suppres
217- Write-O
218- PSUseSingularNouns Warning 1 The cmd
219- noun sh
220+ RuleName Severity FileName Line Message
221+ -------- -------- -------- ---- -------
222+ PSAvoidUsingWriteHost Warning 1 Script definition uses Write-Host. Avoid using
223+ Write-Host because it might not work in all hosts,
224+ does not work when there is no host, and (prior
225+ to PS 5.0) cannot be suppressed, captured, or
226+ redirected. Instead, use Write-Output, Write-Verbose,
227+ or Write-Information.
228+ PSUseSingularNouns Warning 1 The cmdlet 'Get-Widgets' uses a plural noun. A
229+ singular noun should be used instead.
220230```
221231
222232When you use the ** ScriptDefinition** parameter, the ** FileName** property of the
@@ -513,7 +523,7 @@ following keys:
513523
514524The keys and values in the profile are interpreted as if they were standard parameters and values of
515525` Invoke-ScriptAnalyzer` , similar to splatting. For more information, see
516- [about_Splatting](https://learn.microsoft.com /powershell/module/microsoft.powershell.core/about/about_splatting).
526+ [about_Splatting](/powershell/module/microsoft.powershell.core/about/about_splatting).
517527
518528` ` ` yaml
519529Type: Object
@@ -536,15 +546,14 @@ Valid values are:
536546
537547- Error
538548- Warning
539- - Information.
540-
541- You can specify one ore more severity values.
549+ - Information
550+ - ParseError
542551
543- The parameter filters the rules violations only after running all rules. To filter rules
544- efficiently, use `Get-ScriptAnalyzerRule` to select the rules you want to run.
552+ You can specify one or more severity values.
545553
546- The **Severity** parameter takes precedence over **IncludeRule**. For example, if **Severity** is
547- ` Error` , you cannot use **IncludeRule** to include a `Warning` rule.
554+ The parameter filters the rule violation output only after running all rules. It doesn't filter
555+ which rules are run. To filter rules efficiently, use `Get-ScriptAnalyzerRule` to select the rules
556+ you want to run.
548557
549558` ` ` yaml
550559Type: String[]
0 commit comments