Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: This article describes various features of PSScriptAnalyzer and how to use them.
ms.date: 01/28/2026
ms.date: 08/24/2026
title: Using PSScriptAnalyzer
---
# Using PSScriptAnalyzer
Expand Down Expand Up @@ -156,56 +156,71 @@ Param()
You can create settings that describe the ScriptAnalyzer rules to include or exclude based on
**Severity**. Use the **Settings** parameter of `Invoke-ScriptAnalyzer` to specify configuration.
The **Settings** parameter allows you to create a custom configuration for a specific environment.
ScriptAnalyzer support the following modes for specifying the settings file:

This parameter accepts the following types of objects:

- A path to a `.psd1` file containing a user-defined profile
- A hashtable object containing settings
- The name of a built-in preset

### Built-in Presets

ScriptAnalyzer ships a set of built-in presets that can be used to analyze scripts. For example, if
you want to run _PowerShell Gallery_ rules on your module, use the following command:
ScriptAnalyzer ships a set of built-in presets that can be used to analyze scripts. The
PSScriptAnalyzer module includes a set of built-in presets that you can use with the **Settings**
parameter. For example, if you want to run _PowerShell Gallery_ rules on your module, use the
following command:

```powershell
Invoke-ScriptAnalyzer -Path /path/to/module/ -Settings PSGallery -Recurse
```

Additionally, you can use other built-in presets, including **DSC** and **CodeFormatting**.
These presets can be tab completed for the **Settings** parameter.

### Explicit

The following example excludes two rules from the default set of rules and any rule with a
severity other than **Error** and **Warning**.
You can specify multiple presets by separating them with a comma. You can use tab completion to see
the available presets. The built-in presets are stored in the `Settings` folder of the
**PSScriptAnalyzer** module. You can list the built-in presets by running the following command:

```powershell
# PSScriptAnalyzerSettings.psd1
@{
Severity=@('Error','Warning')
ExcludeRules=@('PSAvoidUsingCmdletAliases', 'PSAvoidUsingWriteHost')
}
Get-ChildItem "$($(Get-Module PSScriptAnalyzer).ModuleBase)\Settings\*.psd1"
```

You can then invoke that settings file with `Invoke-ScriptAnalyzer`:

```powershell
Invoke-ScriptAnalyzer -Path MyScript.ps1 -Settings PSScriptAnalyzerSettings.psd1
```Output
Directory: C:\Users\sewhee\Documents\PowerShell\Modules\psscriptAnalyzer\1.25.0\Settings

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 3/20/2026 6:41 PM 15025 CmdletDesign.psd1
-a--- 3/20/2026 6:41 PM 16330 CodeFormatting.psd1
-a--- 3/20/2026 6:41 PM 16331 CodeFormattingAllman.psd1
-a--- 3/20/2026 6:41 PM 16331 CodeFormattingOTBS.psd1
-a--- 3/20/2026 6:41 PM 16375 CodeFormattingStroustrup.psd1
-a--- 3/20/2026 6:41 PM 14674 DSC.psd1
-a--- 3/20/2026 6:41 PM 15735 PSGallery.psd1
-a--- 3/20/2026 6:41 PM 15157 ScriptFunctions.psd1
-a--- 3/20/2026 6:41 PM 14736 ScriptingStyle.psd1
-a--- 3/20/2026 6:41 PM 14985 ScriptSecurity.psd1
```

The next example selects a few rules to execute instead of all the default rules.
To see the rules included in a preset, you can open the `.psd1` file in a text editor.

### Explicit

The following example shows how to invoke Script Analyzer with settings that exclude two rules from
the default set of rules and any rule with a severity other than **Error** and **Warning**.

```powershell
# PSScriptAnalyzerSettings.psd1
@{
IncludeRules=@('PSAvoidUsingPlainTextForPassword',
'PSAvoidUsingConvertToSecureStringWithPlainText')
$pssaSettings = @{
Severity=@('Error','Warning')
ExcludeRules=@('PSAvoidUsingCmdletAliases', 'PSAvoidUsingWriteHost')
}
Invoke-ScriptAnalyzer -Path MyScript.ps1 -Settings $pssaSettings
```

You can then invoke that settings file:
You could also save that hashtable to a `.psd1` file and then invoke Script Analyzer with that settings file.

```powershell
Invoke-ScriptAnalyzer -Path MyScript.ps1 -Settings PSScriptAnalyzerSettings.psd1
```

### Implicit
### Implicit search

If you place a settings file named `PSScriptAnalyzerSettings.psd1` in your project root,
**PSScriptAnalyzer** discovers it when you pass the project root as the **Path** parameter.
Expand Down
118 changes: 72 additions & 46 deletions reference/ps-modules/PSScriptAnalyzer/Get-ScriptAnalyzerRule.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
---
document type: cmdlet
external help file: Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml
HelpUri: https://learn.microsoft.com/powershell/module/psscriptanalyzer/get-scriptanalyzerrule?view=ps-modules&wt.mc_id=ps-gethelp
Module Name: PSScriptAnalyzer
ms.date: 12/12/2024
online version: https://learn.microsoft.com/powershell/module/psscriptanalyzer/get-scriptanalyzerrule?view=ps-modules&wt.mc_id=ps-gethelp
schema: 2.0.0
ms.date: 08/24/2026
PlatyPS schema version: 2024-05-01
---

# Get-ScriptAnalyzerRule

## SYNOPSIS

Gets the script analyzer rules on the local computer.

## SYNTAX

### __AllParameterSets

```
Get-ScriptAnalyzerRule [[-Name] <string[]>] [-CustomRulePath <string[]>] [-RecurseCustomRulePath]
[-Severity <string[]>] [<CommonParameters>]
[-Severity <string[]>]
```

## ALIASES

## DESCRIPTION

Gets the script analyzer rules on the local computer. You can select rules by Name, Severity,
Expand Down Expand Up @@ -96,15 +102,21 @@ You can create custom rules using a .NET assembly or a PowerShell module, such a
in the GitHub repository.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases: CustomizedRulePath

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
Type: System.String[]
DefaultValue: None
SupportsWildcards: true
Aliases:
- CustomizedRulePath
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### -Name
Expand All @@ -113,15 +125,20 @@ Gets only rules with the specified names or name patterns. Wildcards are support
multiple names or patterns, it gets all rules that match any of the name patterns.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: All rules
Accept pipeline input: False
Accept wildcard characters: True
Type: System.String[]
DefaultValue: All rules
SupportsWildcards: true
Aliases: []
ParameterSets:
- Name: (All)
Position: 1
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### -RecurseCustomRulePath
Expand All @@ -130,15 +147,20 @@ Searches the **CustomRulePath** location recursively to add rules defined in fil
of the path. By default, `Get-ScriptAnalyzerRule` adds only the custom rules in the specified path.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### -Severity
Expand All @@ -150,23 +172,28 @@ Gets only rules with the specified severity values. Valid values are:
- Error

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: All rules
Accept pipeline input: False
Accept wildcard characters: False
Type: System.String[]
DefaultValue: All rules
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
-WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand All @@ -184,6 +211,5 @@ The **RuleInfo** object is a custom object created specifically for Script Analy

## RELATED LINKS

[Invoke-ScriptAnalyzer](Invoke-ScriptAnalyzer.md)

[PSScriptAnalyzer on GitHub](https://github.com/PowerShell/PSScriptAnalyzer)
- [Invoke-ScriptAnalyzer](Invoke-ScriptAnalyzer.md)
- [PSScriptAnalyzer on GitHub](https://github.com/PowerShell/PSScriptAnalyzer)
Loading
Loading