Skip to content

Select-Object -ExpandProperty fails with special property names like "[JVN] CVE" #25509

@miriorg

Description

@miriorg

Prerequisites

Steps to reproduce

The issue occurs when using Select-Object -ExpandProperty with a property name that contains special characters like [, ], or spaces. For example:

# Sample CSV file
$csvContent = @"
[JVN] Title,[JVN] CVE
"Some title1",CVE-2023-1234
"Some title2",CVE-2023-5678
"@

# Import CSV
$csv = $csvContent | ConvertFrom-Csv

# Attempt to expand property
$csv | Select-Object -ExpandProperty "[JVN] Title"

Expected behavior

The command should return the values of the `[JVN] Title` property without errors:

Some title1
Some title2

Actual behavior

The following error occurs:

Select-Object: Property "[JVN] Title" cannot be found.

Error details

- The property `[JVN] Title` exists in the object, as confirmed by:

$csv[0].PSObject.Properties | Select-Object -Property Name

- Using `ForEach-Object` to access the property works as expected:

$csv | ForEach-Object { $_.'[JVN] Title' }


This suggests that `-ExpandProperty` may not handle special characters in property names correctly.

Environment data

PS C:\Users\user1> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.5.1
PSEdition                      Core
GitCommitId                    7.5.1
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS C:\Users\user1>

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By DesignThe reported behavior is by design.WG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions