diff --git a/reference/docs-conceptual/PSScriptAnalyzer/using-scriptanalyzer.md b/reference/docs-conceptual/PSScriptAnalyzer/using-scriptanalyzer.md index 606335d..3814fc7 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/using-scriptanalyzer.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/using-scriptanalyzer.md @@ -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 @@ -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. diff --git a/reference/ps-modules/PSScriptAnalyzer/Get-ScriptAnalyzerRule.md b/reference/ps-modules/PSScriptAnalyzer/Get-ScriptAnalyzerRule.md index 3d815b2..0b8b46f 100644 --- a/reference/ps-modules/PSScriptAnalyzer/Get-ScriptAnalyzerRule.md +++ b/reference/ps-modules/PSScriptAnalyzer/Get-ScriptAnalyzerRule.md @@ -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] ] [-CustomRulePath ] [-RecurseCustomRulePath] - [-Severity ] [] + [-Severity ] ``` +## ALIASES + ## DESCRIPTION Gets the script analyzer rules on the local computer. You can select rules by Name, Severity, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/reference/ps-modules/PSScriptAnalyzer/Invoke-Formatter.md b/reference/ps-modules/PSScriptAnalyzer/Invoke-Formatter.md index 80711b0..028e653 100644 --- a/reference/ps-modules/PSScriptAnalyzer/Invoke-Formatter.md +++ b/reference/ps-modules/PSScriptAnalyzer/Invoke-Formatter.md @@ -1,9 +1,10 @@ --- +document type: cmdlet external help file: Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml +HelpUri: https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-formatter?view=ps-modules&wt.mc_id=ps-gethelp Module Name: PSScriptAnalyzer -ms.date: 10/07/2021 -online version: https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-formatter?view=ps-modules&wt.mc_id=ps-gethelp -schema: 2.0.0 +ms.date: 08/24/2026 +PlatyPS schema version: 2024-05-01 --- # Invoke-Formatter @@ -14,11 +15,14 @@ Formats a script text based on the input settings or default settings. ## SYNTAX +### __AllParameterSets + ``` Invoke-Formatter [-ScriptDefinition] [[-Settings] ] [[-Range] ] - [] ``` +## ALIASES + ## DESCRIPTION The `Invoke-Formatter` cmdlet takes a string input and formats it according to defined settings. If @@ -97,15 +101,20 @@ values in this order: - ending column number ```yaml -Type: Int32[] -Parameter Sets: (All) -Aliases: - -Required: False -Position: 3 -Default value: None -Accept pipeline input: True -Accept wildcard characters: False +Type: System.Int32[] +DefaultValue: None +SupportsWildcards: false +Aliases: [] +ParameterSets: +- Name: (All) + Position: 3 + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: true + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -ScriptDefinition @@ -114,15 +123,20 @@ The text of the script to be formatted represented as a string. This is not a ** object. ```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False +Type: System.String +DefaultValue: None +SupportsWildcards: false +Aliases: [] +ParameterSets: +- Name: (All) + Position: 1 + IsRequired: true + ValueFromPipeline: true + ValueFromPipelineByPropertyName: true + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -Settings @@ -130,26 +144,43 @@ Accept wildcard characters: False A settings hashtable or a path to a PowerShell data file (`.psd1`) that contains the settings. ```yaml -Type: Object -Parameter Sets: (All) -Aliases: - -Required: False -Position: 2 -Default value: CodeFormatting -Accept pipeline input: True -Accept wildcard characters: False +Type: System.Object +DefaultValue: CodeFormatting +SupportsWildcards: false +Aliases: [] +ParameterSets: +- Name: (All) + Position: 2 + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: true + 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 +### System.String + +The **ScriptDefinition** parameter accepts a string from the pipeline. + +### System.Object + +The **Settings** parameter accepts values from the pipeline. + +### System.Int32[] + +The **Range** parameter accepts input from the pipeline. + ## OUTPUTS ### System.String @@ -159,3 +190,5 @@ The formatted string result. ## NOTES ## RELATED LINKS + +- [Using PSScriptAnalyzer](/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer) diff --git a/reference/ps-modules/PSScriptAnalyzer/Invoke-ScriptAnalyzer.md b/reference/ps-modules/PSScriptAnalyzer/Invoke-ScriptAnalyzer.md index f1350a2..e7b1788 100644 --- a/reference/ps-modules/PSScriptAnalyzer/Invoke-ScriptAnalyzer.md +++ b/reference/ps-modules/PSScriptAnalyzer/Invoke-ScriptAnalyzer.md @@ -1,14 +1,16 @@ --- +document type: cmdlet external help file: Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml +HelpUri: https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-scriptanalyzer?view=ps-modules&wt.mc_id=ps-gethelp Module Name: PSScriptAnalyzer -ms.date: 07/23/2026 -online version: https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-scriptanalyzer?view=ps-modules&wt.mc_id=ps-gethelp -schema: 2.0.0 +ms.date: 08/24/2026 +PlatyPS schema version: 2024-05-01 --- # Invoke-ScriptAnalyzer ## SYNOPSIS + Evaluates a script or module based on selected best practice rules ## SYNTAX @@ -26,31 +28,31 @@ Invoke-ScriptAnalyzer [-Path] [-CustomRulePath ] [-RecurseCus ``` Invoke-ScriptAnalyzer [-Path] -IncludeSuppressed [-CustomRulePath ] - [-RecurseCustomRulePath] [-IncludeDefaultRules] [-ExcludeRule ] - [-IncludeRule ] [-Severity ] [-Recurse] [-Fix] [-EnableExit] - [-Settings ] [-SaveDscDependency] [-ReportSummary] [-WhatIf] [-Confirm] - [] + [-RecurseCustomRulePath] [-IncludeDefaultRules] [-ExcludeRule ] [-IncludeRule ] + [-Severity ] [-Recurse] [-Fix] [-EnableExit] [-Settings ] [-SaveDscDependency] + [-ReportSummary] [-WhatIf] [-Confirm] ``` ### ScriptDefinition_IncludeSuppressed ``` Invoke-ScriptAnalyzer [-ScriptDefinition] -IncludeSuppressed [-CustomRulePath ] - [-RecurseCustomRulePath] [-IncludeDefaultRules] [-ExcludeRule ] - [-IncludeRule ] [-Severity ] [-Recurse] [-EnableExit] [-Settings ] - [-SaveDscDependency] [-ReportSummary] [-WhatIf] [-Confirm] [] + [-RecurseCustomRulePath] [-IncludeDefaultRules] [-ExcludeRule ] [-IncludeRule ] + [-Severity ] [-Recurse] [-EnableExit] [-Settings ] [-SaveDscDependency] + [-ReportSummary] [-WhatIf] [-Confirm] ``` ### ScriptDefinition_SuppressedOnly ``` Invoke-ScriptAnalyzer [-ScriptDefinition] [-CustomRulePath ] - [-RecurseCustomRulePath] [-IncludeDefaultRules] [-ExcludeRule ] - [-IncludeRule ] [-Severity ] [-Recurse] [-SuppressedOnly] [-EnableExit] - [-Settings ] [-SaveDscDependency] [-ReportSummary] [-WhatIf] [-Confirm] - [] + [-RecurseCustomRulePath] [-IncludeDefaultRules] [-ExcludeRule ] [-IncludeRule ] + [-Severity ] [-Recurse] [-SuppressedOnly] [-EnableExit] [-Settings ] + [-SaveDscDependency] [-ReportSummary] [-WhatIf] [-Confirm] [] ``` +## ALIASES + ## DESCRIPTION `Invoke-ScriptAnalyzer` evaluates scripts or module files (`.ps1`, `.psm1`, and `.psd1` files) based @@ -234,6 +236,28 @@ When you use the **ScriptDefinition** parameter, the **FileName** property of th ## PARAMETERS +### -Confirm + +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +DefaultValue: False +SupportsWildcards: false +Aliases: +- cf +ParameterSets: +- Name: (All) + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' +``` + ### -CustomRulePath Enter the path to a file that defines rules or a directory that contains files that define rules. @@ -245,15 +269,21 @@ To add rules defined in subdirectories of the path, use the **RecurseCustomRuleP include the built-in rules, add the **IncludeDefaultRules** parameter. ```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: '' ``` ### -EnableExit @@ -262,15 +292,20 @@ On completion of the analysis, this parameter exits the PowerShell sessions and equal to the number of error records. This can be useful in continuous integration (CI) pipeline. ```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: '' ``` ### -ExcludeRule @@ -289,15 +324,20 @@ If a rule is specified in both the **ExcludeRule** and **IncludeRule** collectio excluded. ```yaml -Type: String[] -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: All rules are included. -Accept pipeline input: False -Accept wildcard characters: True +Type: System.String[] +DefaultValue: All rules are included. +SupportsWildcards: true +Aliases: [] +ParameterSets: +- Name: (All) + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -Fix @@ -309,15 +349,26 @@ sure that you have a backup of your files when using this parameter. It tries to encoding but there are still some cases where the encoding can change. ```yaml -Type: SwitchParameter -Parameter Sets: Path_SuppressedOnly, Path_IncludeSuppressed -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: Path_IncludeSuppressed + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +- Name: Path_SuppressedOnly + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -IncludeDefaultRules @@ -325,15 +376,20 @@ Accept wildcard characters: False Invoke default rules along with Custom rules. ```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: '' ``` ### -IncludeRule @@ -355,15 +411,20 @@ The **Severity** parameter takes precedence over **IncludeRule**. For example, i `Error`, you cannot use **IncludeRule** to include a `Warning` rule. ```yaml -Type: String[] -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: All rules are included. -Accept pipeline input: False -Accept wildcard characters: True +Type: System.String[] +DefaultValue: All rules are included. +SupportsWildcards: true +Aliases: [] +ParameterSets: +- Name: (All) + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -IncludeSuppressed @@ -371,15 +432,26 @@ Accept wildcard characters: True Include suppressed diagnostics in output. ```yaml -Type: SwitchParameter -Parameter Sets: Path_IncludeSuppressed, ScriptDefinition_IncludeSuppressed -Aliases: - -Required: True -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: Path_IncludeSuppressed + Position: Named + IsRequired: true + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +- Name: ScriptDefinition_IncludeSuppressed + Position: Named + IsRequired: true + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -Path @@ -393,15 +465,27 @@ To analyze files that are not in the root directory of the specified path, use a (`C:\Modules\MyModule\*`) or the **Recurse** parameter. ```yaml -Type: String -Parameter Sets: Path_SuppressedOnly, Path_IncludeSuppressed -Aliases: PSPath - -Required: True -Position: 0 -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: True +Type: System.String +DefaultValue: None +SupportsWildcards: true +Aliases: +- PSPath +ParameterSets: +- Name: Path_IncludeSuppressed + Position: 0 + IsRequired: true + ValueFromPipeline: true + ValueFromPipelineByPropertyName: true + ValueFromRemainingArguments: false +- Name: Path_SuppressedOnly + Position: 0 + IsRequired: true + ValueFromPipeline: true + ValueFromPipelineByPropertyName: true + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -Recurse @@ -412,15 +496,20 @@ Recurse applies only to the Path parameter value. To search the **CustomRulePath the **RecurseCustomRulePath** parameter. ```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: '' ``` ### -RecurseCustomRulePath @@ -430,15 +519,20 @@ Adds rules defined in subdirectories of the **CustomRulePath** location. By defa include the built-in rules, use the **IncludeDefaultRules** parameter. ```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: '' ``` ### -ReportSummary @@ -446,15 +540,20 @@ Accept wildcard characters: False Write a summary of the violations found to the host. ```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: '' ``` ### -SaveDscDependency @@ -471,15 +570,20 @@ module to a temp path. The temp path is then added to `$env:PSModulePath` for du The temp location can be found in `$LOCALAPPDATA/PSScriptAnalyzer/TempModuleDir`. ```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: '' ``` ### -ScriptDefinition @@ -488,53 +592,57 @@ Runs the analysis on commands, functions, or expressions in a string. You can us analyze statements, expressions, and functions, independent of their script context. ```yaml -Type: String -Parameter Sets: ScriptDefinition_IncludeSuppressed, ScriptDefinition_SuppressedOnly -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False +Type: System.String +DefaultValue: None +SupportsWildcards: false +Aliases: [] +ParameterSets: +- Name: ScriptDefinition_IncludeSuppressed + Position: 0 + IsRequired: true + ValueFromPipeline: true + ValueFromPipelineByPropertyName: true + ValueFromRemainingArguments: false +- Name: ScriptDefinition_SuppressedOnly + Position: 0 + IsRequired: true + ValueFromPipeline: true + ValueFromPipelineByPropertyName: true + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -Settings -A path to a file containing a user-defined profile or a hashtable object containing settings for -ScriptAnalyzer. +Runs `Invoke-ScriptAnalyzer` with the parameters and values specified. This parameter accepts the +following types of objects: -Runs `Invoke-ScriptAnalyzer` with the parameters and values specified in the file or hashtable. +- A path to a `.psd1` file containing a user-defined profile +- A hashtable object containing settings +- The name of a built-in preset -If the path or the content of the file or hashtable is invalid, it is ignored. The parameters and -values in the profile take precedence over the same parameter and values specified at the command -line. - -A Script Analyzer profile file is a text file that contains a hashtable with one or more of the -following keys: - -- CustomRulePath -- ExcludeRules -- IncludeDefaultRules -- IncludeRules -- RecurseCustomRulePath -- Rules -- Severity - -The keys and values in the profile are interpreted as if they were standard parameters and values of -`Invoke-ScriptAnalyzer`, similar to splatting. For more information, see -[about_Splatting](/powershell/module/microsoft.powershell.core/about/about_splatting). +The parameters and values in the profile take precedence over the same parameter and values +specified at the command line. Invalid values are ignored. You can specify multiple presets by +separating them with a comma. You can use tab completion to see the available presets. ```yaml -Type: Object -Parameter Sets: (All) -Aliases: Profile - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False +Type: System.Object +DefaultValue: None +SupportsWildcards: false +Aliases: +- Profile +ParameterSets: +- Name: (All) + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -Severity @@ -556,15 +664,20 @@ which rules are run. To filter rules efficiently, use `Get-ScriptAnalyzerRule` t you want to run. ```yaml -Type: String[] -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: All rule violations -Accept pipeline input: False -Accept wildcard characters: False +Type: System.String[] +DefaultValue: All rule violations +SupportsWildcards: false +Aliases: [] +ParameterSets: +- Name: (All) + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -SuppressedOnly @@ -577,31 +690,26 @@ Returns a **SuppressedRecord** object To suppress a rule, use the **SuppressMessageAttribute**. For help, see the examples. ```yaml -Type: SwitchParameter -Parameter Sets: Path_SuppressedOnly, ScriptDefinition_SuppressedOnly -Aliases: - -Required: False -Position: Named -Default value: False -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Confirm - -Prompts you for confirmation before running the cmdlet. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: cf - -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: Path_SuppressedOnly + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +- Name: ScriptDefinition_SuppressedOnly + Position: Named + IsRequired: false + ValueFromPipeline: false + ValueFromPipelineByPropertyName: false + ValueFromRemainingArguments: false +DontShow: false +AcceptedValues: [] +HelpMessage: '' ``` ### -WhatIf @@ -609,29 +717,35 @@ Accept wildcard characters: False Shows what would happen if the cmdlet runs. The cmdlet is not run. ```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: wi - -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: +- wi +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 -### None +### System.String -You cannot pipe input to this cmdlet. +The **Path** and **ScriptDefinition** parameters accept a string values from the pipeline. ## OUTPUTS @@ -646,8 +760,40 @@ If you use the **SuppressedOnly** parameter, `Invoke-ScriptAnalyzer` instead ret ## NOTES -## RELATED LINKS +A Script Analyzer profile file is a `.psd1` file that contains a hashtable with one or more of the +following keys: -[Get-ScriptAnalyzerRule](Get-ScriptAnalyzerRule.md) +- CustomRulePath +- ExcludeRules +- IncludeDefaultRules +- IncludeRules +- RecurseCustomRulePath +- Rules +- Severity + +The keys and values in the profile are interpreted as if they were standard parameters and values of +`Invoke-ScriptAnalyzer`, similar to splatting. For more information, see +[about_Splatting](/powershell/module/microsoft.powershell.core/about/about_splatting). + +The PSScriptAnalyzer module includes a set of built-in presets that you can use with the +**Settings** parameter. The built-in presets are: + +- CmdletDesign +- CodeFormatting +- CodeFormattingAllman +- CodeFormattingOTBS +- CodeFormattingStroustrup +- DSC +- PSGallery +- ScriptFunctions +- ScriptingStyle +- ScriptSecurity + +You can specify multiple presets by separating them with a comma. You can use tab completion to see +the available presets. + +## RELATED LINKS -[PSScriptAnalyzer on GitHub](https://github.com/PowerShell/PSScriptAnalyzer) +- [Get-ScriptAnalyzerRule](Get-ScriptAnalyzerRule.md) +- [PSScriptAnalyzer on GitHub](https://github.com/PowerShell/PSScriptAnalyzer) +- [Using PSScriptAnalyzer](/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer)