Skip to content

PSAvoidAssignmentToAutomaticVariable triggers on property assignment of automatic variable #1012

Closed
@SeeminglyScience

Description

@SeeminglyScience

Steps to reproduce

Invoke-ScriptAnalyzer -ScriptDefinition '$ExecutionContext.SessionState.Module.OnRemove = {}'

Expected behavior

No output.

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidAssignmentToAutomaticVariable Error                   1     The Variable 'ExecutionContext' cannot be assigned
                                                                  since it is a readonly automatic variable that is
                                                                  built into PowerShell, please use a different name.

Environment data

> $PSVersionTable
 
Name                           Value                                                                                                                                                         
----                           -----                                                                                                                                                         
PSVersion                      5.1.16299.251                                                                                                                                                 
PSEdition                      Desktop                                                                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                       
BuildVersion                   10.0.16299.251                                                                                                                                                
CLRVersion                     4.0.30319.42000                                                                                                                                               
WSManStackVersion              3.0                                                                                                                                                           
PSRemotingProtocolVersion      2.3                                                                                                                                                           
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.17.0
1.13.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions