Skip to content

Get-Command fails with unexpected error when given a blank command-name argument #13342

@mklement0

Description

@mklement0

Note: This is definitely a minor bug that won't arise too often in the real world.

Passing an all-whitespace -Name argument to Get-Command results in unexpected error message Get-Command: Index was outside the bounds of the array.

Steps to reproduce

{ Get-Command -ea Stop -Name ' '  } | Should -Throw -ErrorId CommandNotFoundException

Expected behavior

The test should succeed; that is, the usual CommandNotFoundException should be reported.

Actual behavior

The test fails, because the error mentioned above is reported instead.

Expected an exception, with FullyQualifiedErrorId 'CommandNotFoundException' to be thrown, 
but the FullyQualifiedErrorId was 
'System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.GetCommandCommand'

Environment data

PowerShell Core 7.1.0-preview.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    First-Time-IssueEasy issues first time contributors can work on to learn about this projectIssue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions