Group-Object “Wildcard characters are not allowed in …”


I recently came across a situation where I wanted to group a custom object based on a property that contained a question mark.

[PSCustomObject]@{"test?"="test"} |
     group 'test?'

Running the above resulted in the error message “group : Wildcard characters are not allowed in “test?”.”. To make Group-Object work with the property name that contains a wildcard character the property name needs to be escaped either manually by preceding the wildcard character by “`” (e.g. “test`?”) or utilizing the related .net method.

[PSCustomObject]@{"test?"="test"} |
     group [Management.Automation.WildcardPattern]::Escape('test?'))


photo credit: the tree II via photopin (license)


I'd love to hear what you think

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s