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

tree2

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?'))

shareThoughts


photo credit: the tree II via photopin (license)

Advertisements

I'd love to hear what you think

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

WordPress.com Logo

You are commenting using your WordPress.com 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