From 8f0d2efe2cc21dd12b80fe1b0d0c55263e92f4e7 Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Thu, 28 May 2026 19:20:38 -0400 Subject: [PATCH 1/5] Freshness --- .../Rules/AvoidExclaimOperator.md | 24 +++++++++---------- .../Rules/AvoidGlobalAliases.md | 23 +++++++++--------- .../Rules/AvoidGlobalFunctions.md | 20 +++++++++------- .../PSScriptAnalyzer/Rules/AvoidGlobalVars.md | 17 ++++++------- .../Rules/AvoidInvokingEmptyMembers.md | 15 ++++++------ 5 files changed, 50 insertions(+), 49 deletions(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md index 11d078d..d61719d 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md @@ -1,6 +1,6 @@ --- description: Avoid exclaim operator -ms.date: 03/26/2024 +ms.date: 05/28/2026 ms.topic: reference title: AvoidExclaimOperator --- @@ -10,22 +10,24 @@ title: AvoidExclaimOperator ## Description -Avoid using the negation operator (`!`). Use `-not` for improved readability. +This rule detects the use of the negation operator (`!`) and recommends using the `-not` +operator instead for improved readability and consistency with PowerShell conventions. -> [!NOTE] -> This rule is not enabled by default. The user needs to enable it through settings. +The `-not` operator is more explicit and aligns with PowerShell's verbose style, making code +easier to understand at a glance. -## How to Fix +This rule is **disabled** by default. Enable it explicitly during ScriptAnalyzer invocation if +desired. ## Example -### Wrong +### Noncompliant ```powershell $MyVar = !$true ``` -### Correct +### Preferred ```powershell $MyVar = -not $true @@ -33,6 +35,8 @@ $MyVar = -not $true ## Configuration +To enable this rule, run the following command: + ```powershell Rules = @{ PSAvoidExclaimOperator = @{ @@ -40,9 +44,3 @@ Rules = @{ } } ``` - -### Parameters - -- `Enable`: **bool** (Default value is `$false`) - - Enable or disable the rule during ScriptAnalyzer invocation. diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md index 5157ec6..2316ca8 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md @@ -1,6 +1,6 @@ --- description: Avoid global aliases. -ms.date: 06/28/2023 +ms.date: 05/28/2026 ms.topic: reference title: AvoidGlobalAliases --- @@ -10,28 +10,29 @@ title: AvoidGlobalAliases ## Description -Globally scoped aliases override existing aliases within the sessions with matching names. This name -collision can cause difficult to debug issues for consumers of modules and scripts. +Global aliases can override existing aliases in the current session. This override +creates naming conflicts that lead to hard to diagnose problems for module and script consumers. -To understand more about scoping, see `Get-Help about_Scopes`. - -**NOTE** This rule is not available in PowerShell version 3 or 4 because it uses the +This rule is not available in PowerShell version 3 or 4 because it uses the `StaticParameterBinder.BindCommand` API. -## How - -Use other scope modifiers for new aliases. +Instead of using the Global scope, use other scope modifiers such as `Local` or `Process` when +creating new aliases. To learn more, see [about_Scopes][01]. ## Example -### Wrong +### Noncompliant ```powershell New-Alias -Name Name -Value Value -Scope Global ``` -### Correct +### Compliant ```powershell New-Alias -Name Name1 -Value Value ``` + + + +[01]: /powershell/module/microsoft.powershell.core/about/about_scopes diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md index 929466c..9732d81 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md @@ -10,25 +10,27 @@ title: AvoidGlobalFunctions ## Description -Globally scoped functions override existing functions within the sessions with matching names. This -name collision can cause difficult to debug issues for consumers of modules. +Global functions can unintentionally override existing functions in the session, leading to +unexpected behavior and name collisions. Name collisions makes it difficult for module consumers to +diagnose issues and maintain code reliability. -To understand more about scoping, see `Get-Help about_Scopes`. - -## How - -Use other scope modifiers for functions. +To avoid this issue, define functions without the global scope modifier, or use other appropriate +scope modifiers. To learn more, see [about_Scopes][01]. ## Example -### Wrong +### Noncompliant ```powershell function global:functionName {} ``` -### Correct +### Compliant ```powershell function functionName {} ``` + + + +[01]: /powershell/module/microsoft.powershell.core/about/about_scopes diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md index 7fa0f6d..d7aa8aa 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md @@ -1,6 +1,6 @@ --- description: No Global Variables -ms.date: 06/28/2023 +ms.date: 05/28/2026 ms.topic: reference title: AvoidGlobalVars --- @@ -20,15 +20,12 @@ Globally scoped variables include: - Preference variables - Variables, aliases, and functions that are in your PowerShell profiles -To understand more about scoping, see `Get-Help about_Scopes`. - -## How - -Use other scope modifiers for variables. +Use local or script scope for variables instead of global scope. To learn more, see +[about_Scopes][01]. ## Example -### Wrong +### Noncompliant ```powershell $Global:var1 = $null @@ -38,7 +35,7 @@ function Test-NotGlobal ($var) } ``` -### Correct +### Compliant ```powershell $var1 = $null @@ -47,3 +44,7 @@ function Test-NotGlobal ($var1, $var2) $a = $var1 + $var2 } ``` + + + +[01]: /powershell/module/microsoft.powershell.core/about/about_scopes diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md index 6049e86..1654095 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md @@ -1,6 +1,6 @@ --- description: Avoid Invoking Empty Members -ms.date: 06/28/2023 +ms.date: 05/28/2026 ms.topic: reference title: AvoidInvokingEmptyMembers --- @@ -10,23 +10,22 @@ title: AvoidInvokingEmptyMembers ## Description -Invoking non-constant members can cause potential bugs. Please double check the syntax to make sure -that invoked members are constants. +Invoking dynamically constructed member names can introduce unexpected behavior and runtime errors. +Ensure that member invocations use constant, literal member names rather than expressions that are +evaluated at runtime. -## How - -Provide the requested members for a given type or class. +Replace dynamic member name expressions with constant member names for the target type or class. ## Example -### Wrong +### Noncompliant ```powershell $MyString = 'abc' $MyString.('len'+'gth') ``` -### Correct +### Compliant ```powershell $MyString = 'abc' From 833569ed4771fa1064085e8bb312afe6c3b10dc3 Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Thu, 28 May 2026 19:46:10 -0400 Subject: [PATCH 2/5] Add AvoidExclaimOperator to TOC --- reference/docs-conceptual/toc.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reference/docs-conceptual/toc.yml b/reference/docs-conceptual/toc.yml index 1fbfbd3..7f05ada 100644 --- a/reference/docs-conceptual/toc.yml +++ b/reference/docs-conceptual/toc.yml @@ -43,6 +43,8 @@ items: href: PSScriptAnalyzer/Rules/AvoidDefaultValueForMandatoryParameter.md - name: AvoidDefaultValueSwitchParameter href: PSScriptAnalyzer/Rules/AvoidDefaultValueSwitchParameter.md + - name: AvoidExclaimOperator + href: PSScriptAnalyzer/Rules/AvoidExclaimOperator.md - name: AvoidGlobalAliases href: PSScriptAnalyzer/Rules/AvoidGlobalAliases.md - name: AvoidGlobalFunctions From b954d393d80d9f9240f9e03e1973274daca1691b Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Thu, 28 May 2026 19:47:35 -0400 Subject: [PATCH 3/5] Heading edit --- .../PSScriptAnalyzer/Rules/AvoidExclaimOperator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md index d61719d..70f0199 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md @@ -27,7 +27,7 @@ desired. $MyVar = !$true ``` -### Preferred +### Compliant ```powershell $MyVar = -not $true From 3bf93ae9618fdb6155c43ecaa4c3cc381b2c5ba3 Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Fri, 29 May 2026 18:44:02 -0400 Subject: [PATCH 4/5] Reintroduce params --- .../PSScriptAnalyzer/Rules/AvoidExclaimOperator.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md index 70f0199..9750509 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md @@ -33,7 +33,7 @@ $MyVar = !$true $MyVar = -not $true ``` -## Configuration +## Configure rule To enable this rule, run the following command: @@ -44,3 +44,13 @@ Rules = @{ } } ``` + +## Parameters + +### Enable + +Enables (`$true`) the rule during ScriptAnalyzer invocation. + +### Disable + +Disables (`$false`) the rule during ScriptAnalyzer invocation. Default value is `$false`. From 80dfe5139127d90560814b38c0554eaff52b6a84 Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Mon, 1 Jun 2026 10:11:10 -0400 Subject: [PATCH 5/5] Applied feedback --- .../PSScriptAnalyzer/Rules/AvoidExclaimOperator.md | 4 ++-- .../PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md index 9750509..a9c5963 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md @@ -10,8 +10,8 @@ title: AvoidExclaimOperator ## Description -This rule detects the use of the negation operator (`!`) and recommends using the `-not` -operator instead for improved readability and consistency with PowerShell conventions. +This rule detects the use of the negation operator exclamation mark (`!`) and recommends using the +`-not` operator instead for improved readability and consistency with PowerShell conventions. The `-not` operator is more explicit and aligns with PowerShell's verbose style, making code easier to understand at a glance. diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md index 9732d81..9f5a4da 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md @@ -11,7 +11,7 @@ title: AvoidGlobalFunctions ## Description Global functions can unintentionally override existing functions in the session, leading to -unexpected behavior and name collisions. Name collisions makes it difficult for module consumers to +unexpected behavior and name collisions. Name collisions make it difficult for module consumers to diagnose issues and maintain code reliability. To avoid this issue, define functions without the global scope modifier, or use other appropriate