Skip to content

Wrong parameter name in the Get-Variable cmdlet error message. #7383

@sethvs

Description

@sethvs

When using Get-Variable (or Get-Alias) cmdlet with the -Scope parameter with wrong value, the error message refers to scopeID parameter.
Even though it is the real parameter of the GetScopeByID and GetScopeByID internal methods, the error message returns to the user, who used the -Scope parameter.

So it would be nice, if the error messages refer to the -Scope parameter.

Steps to reproduce

Get-Variable -Scope 100
Get-Variable -Scope SomeWrongScopeName

Expected behavior

Get-Variable : The scope number '100' exceeds the number of active scopes.
Parameter name: Scope
Actual value was 100.
At line:1 char:1
+ Get-Variable -Scope 100
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-Variable], PSArgumentOutOfRangeException
+ FullyQualifiedErrorId : ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetVariableCommand


Get-Variable : Cannot process argument because the value of parameter "Scope" is not valid.
Valid values are "Global", "Local", or "Script", or a number relative to the current scope 
(0 through the number of scopes where 0 is the current scope and 1 is its parent). 
Change the value of the "Scope" parameter and run the operation again.
At line:1 char:1
+ Get-Variable -Scope SomeWrongScopeName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-Variable], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.GetVariableCommand

Actual behavior

Get-Variable : The scope number '100' exceeds the number of active scopes.
Parameter name: scopeID
Actual value was 100.
At line:1 char:1
+ Get-Variable -Scope 100
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-Variable], PSArgumentOutOfRangeException
+ FullyQualifiedErrorId : ArgumentOutOfRange,Microsoft.PowerShell.Commands.GetVariableCommand


Get-Variable : Cannot process argument because the value of argument "scopeID" is not valid.
Valid values are "Global", "Local", or "Script", or a number relative to the current scope 
(0 through the number of scopes where 0 is the current scope and 1 is its parent). 
Change the value of the "scopeID" argument and run the operation again.
At line:1 char:1
+ Get-Variable -Scope SomeWrongScopeName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-Variable], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.GetVariableCommand

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0-preview.4
PSEdition                      Core
GitCommitId                    6.1.0-preview.4
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions