From e2431055ac66e1879dde649c16d08c22366f9d92 Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Thu, 28 May 2026 13:29:14 -0400 Subject: [PATCH 1/4] Freshness --- .../AvoidAssignmentToAutomaticVariable.md | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md index 60d520d..71eec55 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md @@ -1,6 +1,6 @@ --- description: Changing automatic variables might have undesired side effects -ms.date: 06/28/2023 +ms.date: 05/28/2026 ms.topic: reference title: AvoidAssignmentToAutomaticVariable --- @@ -10,16 +10,14 @@ title: AvoidAssignmentToAutomaticVariable ## Description -PowerShell has built-in variables known as automatic variables. Many of them are read-only and -PowerShell throws an error when trying to assign an value on those. Other automatic variables should -only be assigned in certain special cases to achieve a certain effect as a special technique. +PowerShell automatic variables are built-in variables that store runtime and execution state. +Several automatic variables are read-only, and PowerShell throws an error if you try to assign a +value to them. Assign other automatic variables only in advanced, intentional scenarios. -To understand more about automatic variables, see `Get-Help about_Automatic_Variables`. +This rule helps you avoid conflicts with automatic variable names, which reduces hard-to-diagnose +bugs and keeps function behavior predictable. - +To learn more about automatic variables, see `Get-Help about_Automatic_Variables`. ## How @@ -27,9 +25,9 @@ Use variable names in functions or their parameters that do not conflict with au ## Example -### Wrong +### Noncompliant -The variable `$Error` is an automatic variables that exists in the global scope and should therefore +The variable `$Error` is an automatic variable that exists in the global scope and should therefore never be used as a variable or parameter name. ```powershell @@ -40,7 +38,7 @@ function foo($Error){ } function Get-CustomErrorMessage($ErrorMessage){ $Error = "Error occurred: $ErrorMessage" } ``` -### Correct +### Preferred ```powershell function Get-CustomErrorMessage($ErrorMessage){ $FinalErrorMessage = "Error occurred: $ErrorMessage" } From fb315b95e5b2b35d7820755279530cd37ade93ff Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Thu, 28 May 2026 15:06:08 -0400 Subject: [PATCH 2/4] Minor edit --- .../Rules/AvoidAssignmentToAutomaticVariable.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md index 71eec55..4e2c066 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md @@ -17,11 +17,9 @@ value to them. Assign other automatic variables only in advanced, intentional sc This rule helps you avoid conflicts with automatic variable names, which reduces hard-to-diagnose bugs and keeps function behavior predictable. -To learn more about automatic variables, see `Get-Help about_Automatic_Variables`. - -## How +Use variable names in functions or their parameters that don't conflict with automatic variables. -Use variable names in functions or their parameters that do not conflict with automatic variables. +To learn more about automatic variables, see `Get-Help about_Automatic_Variables`. ## Example From 7799932249cd4e432aa406119cd6bb5f6bf88e78 Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Thu, 28 May 2026 15:45:45 -0400 Subject: [PATCH 3/4] Applied feedback --- .../Rules/AvoidAssignmentToAutomaticVariable.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md index 4e2c066..832abfa 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md @@ -10,16 +10,16 @@ title: AvoidAssignmentToAutomaticVariable ## Description -PowerShell automatic variables are built-in variables that store runtime and execution state. -Several automatic variables are read-only, and PowerShell throws an error if you try to assign a -value to them. Assign other automatic variables only in advanced, intentional scenarios. +PowerShell defines a set of automatic variables that store state information for and are created and +maintained by PowerShell. Even though you _can_ override many automatic variables, doing so can have +unexpected effects for users. Assign automatic variables only in advanced, intentional scenarios. This rule helps you avoid conflicts with automatic variable names, which reduces hard-to-diagnose bugs and keeps function behavior predictable. Use variable names in functions or their parameters that don't conflict with automatic variables. -To learn more about automatic variables, see `Get-Help about_Automatic_Variables`. +To learn more about automatic variables, see [about_Automatic_Variables][01]. ## Example @@ -41,3 +41,7 @@ function Get-CustomErrorMessage($ErrorMessage){ $Error = "Error occurred: $Error ```powershell function Get-CustomErrorMessage($ErrorMessage){ $FinalErrorMessage = "Error occurred: $ErrorMessage" } ``` + + + +[01]: /powershell/module/microsoft.powershell.core/about/about_automatic_variables From d2d47581bf3ac96f430af4b640ab1febbaf36330 Mon Sep 17 00:00:00 2001 From: Xelu86 Date: Thu, 28 May 2026 16:04:44 -0400 Subject: [PATCH 4/4] Applied feedback --- .../Rules/AvoidAssignmentToAutomaticVariable.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md index 832abfa..d3cf990 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md @@ -10,14 +10,14 @@ title: AvoidAssignmentToAutomaticVariable ## Description -PowerShell defines a set of automatic variables that store state information for and are created and -maintained by PowerShell. Even though you _can_ override many automatic variables, doing so can have -unexpected effects for users. Assign automatic variables only in advanced, intentional scenarios. +PowerShell automatically defines variables that store internal state information and manages them on +its own. Even though you _can_ override many automatic variables, doing so can have unexpected +effects for users. Assign automatic variables only in advanced, intentional scenarios. -This rule helps you avoid conflicts with automatic variable names, which reduces hard-to-diagnose -bugs and keeps function behavior predictable. +This rule helps you avoid assignments to automatic variables, which reduces hard-to-diagnose bugs +and keeps function behavior predictable. -Use variable names in functions or their parameters that don't conflict with automatic variables. +Also use variable names in functions or parameters that don't conflict with automatic variables. To learn more about automatic variables, see [about_Automatic_Variables][01].