Skip to content

Commit bdbb8f1

Browse files
authored
Update wildcard support on ExpandProperty parameter (#12335)
1 parent eda46ad commit bdbb8f1

File tree

4 files changed

+160
-140
lines changed

4 files changed

+160
-140
lines changed

reference/5.1/Microsoft.PowerShell.Utility/Select-Object.md

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 06/19/2024
5+
ms.date: 09/03/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-object?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -217,9 +217,9 @@ outputted objects have a specific standard format, the expanded property might n
217217

218218
```powershell
219219
# Create a custom object to use for the Select-Object example.
220-
$object = [pscustomobject]@{Name="CustomObject";Expand=@(1,2,3,4,5)}
220+
$object = [pscustomobject]@{Name="CustomObject";List=@(1,2,3,4,5)}
221221
# Use the ExpandProperty parameter to Expand the property.
222-
$object | Select-Object -ExpandProperty Expand -Property Name
222+
$object | Select-Object -ExpandProperty List -Property Name
223223
```
224224

225225
```Output
@@ -233,35 +233,14 @@ $object | Select-Object -ExpandProperty Expand -Property Name
233233
```powershell
234234
# The output did not contain the Name property, but it was added successfully.
235235
# Use Get-Member to confirm the Name property was added and populated.
236-
$object | Select-Object -ExpandProperty Expand -Property Name | Get-Member
236+
$object | Select-Object -ExpandProperty List -Property Name | Get-Member -MemberType Properties
237237
```
238238

239239
```Output
240240
TypeName: System.Int32
241241
242242
Name MemberType Definition
243243
---- ---------- ----------
244-
CompareTo Method int CompareTo(System.Object value), int CompareTo(int value), ...
245-
Equals Method bool Equals(System.Object obj), bool Equals(int obj), bool IEq...
246-
GetHashCode Method int GetHashCode()
247-
GetType Method type GetType()
248-
GetTypeCode Method System.TypeCode GetTypeCode(), System.TypeCode IConvertible.Ge...
249-
ToBoolean Method bool IConvertible.ToBoolean(System.IFormatProvider provider)
250-
ToByte Method byte IConvertible.ToByte(System.IFormatProvider provider)
251-
ToChar Method char IConvertible.ToChar(System.IFormatProvider provider)
252-
ToDateTime Method datetime IConvertible.ToDateTime(System.IFormatProvider provider)
253-
ToDecimal Method decimal IConvertible.ToDecimal(System.IFormatProvider provider)
254-
ToDouble Method double IConvertible.ToDouble(System.IFormatProvider provider)
255-
ToInt16 Method int16 IConvertible.ToInt16(System.IFormatProvider provider)
256-
ToInt32 Method int IConvertible.ToInt32(System.IFormatProvider provider)
257-
ToInt64 Method long IConvertible.ToInt64(System.IFormatProvider provider)
258-
ToSByte Method sbyte IConvertible.ToSByte(System.IFormatProvider provider)
259-
ToSingle Method float IConvertible.ToSingle(System.IFormatProvider provider)
260-
ToString Method string ToString(), string ToString(string format), string ToS...
261-
ToType Method System.Object IConvertible.ToType(type conversionType, System...
262-
ToUInt16 Method uint16 IConvertible.ToUInt16(System.IFormatProvider provider)
263-
ToUInt32 Method uint32 IConvertible.ToUInt32(System.IFormatProvider provider)
264-
ToUInt64 Method uint64 IConvertible.ToUInt64(System.IFormatProvider provider)
265244
Name NoteProperty string Name=CustomObject
266245
```
267246

@@ -425,6 +404,30 @@ name children
425404
USA @{name=Southwest}
426405
```
427406

407+
### Example 15: Use wildcards with the -ExpandProperty parameter
408+
409+
This example demonstrates using wildcards with the **ExpandProperty** parameter. The wildcard
410+
character must resolve to a single property name. If the wildcard character resolves to more than
411+
one property name, `Select-Object` returns an error.
412+
413+
```powershell
414+
# Create a custom object.
415+
$object = [pscustomobject]@{
416+
Label = "MyObject"
417+
Names = @("John","Jane","Joe")
418+
Numbers = @(1,2,3,4,5)
419+
}
420+
# Try to expand multiple properties using a wildcard.
421+
$object | Select-Object -ExpandProperty N*
422+
Select-Object: Multiple properties cannot be expanded.
423+
424+
# Use a wildcard that resolves to a single property.
425+
$object | Select-Object -ExpandProperty Na*
426+
John
427+
Jane
428+
Joe
429+
```
430+
428431
## PARAMETERS
429432

430433
### -ExcludeProperty
@@ -448,17 +451,19 @@ Accept wildcard characters: True
448451
449452
Specifies a property to select, and indicates that an attempt should be made to expand that
450453
property. If the input object pipeline doesn't have the property named, `Select-Object` returns an
451-
error.
454+
error. This parameter supports wildcards. However, the wildcard character must resolve to a single
455+
property name. If the wildcard character resolves to more than one property name, `Select-Object`
456+
returns an error.
457+
458+
When you use **ExpandProperty**, `Select-Object` attempts to expand the specified property for every
452459

453460
- If the specified property is an array, each value of the array is included in the output.
454461
- If the specified property is an object, the objects properties are expanded for every
455462
**InputObject**
456463

457-
In either case, the output objects' **Type** matches the expanded property's **Type**.
458-
459-
> [!NOTE]
460-
> There is a side-effect when using **ExpandProperty**. The `Select-Object` adds the selected
461-
> properties to the original object as **NoteProperty** members.
464+
In either case, the output objects' **Type** matches the expanded property's **Type**. There is a
465+
side-effect when using **ExpandProperty**. The `Select-Object` adds the selected properties to the
466+
original object as **NoteProperty** members.
462467

463468
If the **Property** parameter is specified, `Select-Object` attempts to add each selected property
464469
as a **NoteProperty** to every outputted object.
@@ -481,7 +486,7 @@ Required: False
481486
Position: Named
482487
Default value: None
483488
Accept pipeline input: False
484-
Accept wildcard characters: False
489+
Accept wildcard characters: True
485490
```
486491

487492
### -First

reference/7.4/Microsoft.PowerShell.Utility/Select-Object.md

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 06/19/2024
5+
ms.date: 09/03/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -240,9 +240,9 @@ outputted objects have a specific standard format, the expanded property might n
240240

241241
```powershell
242242
# Create a custom object to use for the Select-Object example.
243-
$object = [pscustomobject]@{Name="CustomObject";Expand=@(1,2,3,4,5)}
243+
$object = [pscustomobject]@{Name="CustomObject";List=@(1,2,3,4,5)}
244244
# Use the ExpandProperty parameter to Expand the property.
245-
$object | Select-Object -ExpandProperty Expand -Property Name
245+
$object | Select-Object -ExpandProperty List -Property Name
246246
```
247247

248248
```Output
@@ -256,35 +256,14 @@ $object | Select-Object -ExpandProperty Expand -Property Name
256256
```powershell
257257
# The output did not contain the Name property, but it was added successfully.
258258
# Use Get-Member to confirm the Name property was added and populated.
259-
$object | Select-Object -ExpandProperty Expand -Property Name | Get-Member
259+
$object | Select-Object -ExpandProperty List -Property Name | Get-Member -MemberType Properties
260260
```
261261

262262
```Output
263263
TypeName: System.Int32
264264
265265
Name MemberType Definition
266266
---- ---------- ----------
267-
CompareTo Method int CompareTo(System.Object value), int CompareTo(int value), ...
268-
Equals Method bool Equals(System.Object obj), bool Equals(int obj), bool IEq...
269-
GetHashCode Method int GetHashCode()
270-
GetType Method type GetType()
271-
GetTypeCode Method System.TypeCode GetTypeCode(), System.TypeCode IConvertible.Ge...
272-
ToBoolean Method bool IConvertible.ToBoolean(System.IFormatProvider provider)
273-
ToByte Method byte IConvertible.ToByte(System.IFormatProvider provider)
274-
ToChar Method char IConvertible.ToChar(System.IFormatProvider provider)
275-
ToDateTime Method datetime IConvertible.ToDateTime(System.IFormatProvider provider)
276-
ToDecimal Method decimal IConvertible.ToDecimal(System.IFormatProvider provider)
277-
ToDouble Method double IConvertible.ToDouble(System.IFormatProvider provider)
278-
ToInt16 Method int16 IConvertible.ToInt16(System.IFormatProvider provider)
279-
ToInt32 Method int IConvertible.ToInt32(System.IFormatProvider provider)
280-
ToInt64 Method long IConvertible.ToInt64(System.IFormatProvider provider)
281-
ToSByte Method sbyte IConvertible.ToSByte(System.IFormatProvider provider)
282-
ToSingle Method float IConvertible.ToSingle(System.IFormatProvider provider)
283-
ToString Method string ToString(), string ToString(string format), string ToS...
284-
ToType Method System.Object IConvertible.ToType(type conversionType, System...
285-
ToUInt16 Method uint16 IConvertible.ToUInt16(System.IFormatProvider provider)
286-
ToUInt32 Method uint32 IConvertible.ToUInt32(System.IFormatProvider provider)
287-
ToUInt64 Method uint64 IConvertible.ToUInt64(System.IFormatProvider provider)
288267
Name NoteProperty string Name=CustomObject
289268
```
290269

@@ -377,11 +356,11 @@ This example demonstrates the side-effect of using the **ExpandProperty** parame
377356

378357
```powershell
379358
PS> $object = [pscustomobject]@{
380-
name = 'USA'
381-
children = [pscustomobject]@{
382-
name = 'Southwest'
359+
name = 'USA'
360+
children = [pscustomobject]@{
361+
name = 'Southwest'
362+
}
383363
}
384-
}
385364
PS> $object
386365
387366
name children
@@ -444,6 +423,30 @@ name children
444423
USA @{name=Southwest}
445424
```
446425

426+
### Example 16: Use wildcards with the -ExpandProperty parameter
427+
428+
This example demonstrates using wildcards with the **ExpandProperty** parameter. The wildcard
429+
character must resolve to a single property name. If the wildcard character resolves to more than
430+
one property name, `Select-Object` returns an error.
431+
432+
```powershell
433+
# Create a custom object.
434+
$object = [pscustomobject]@{
435+
Label = "MyObject"
436+
Names = @("John","Jane","Joe")
437+
Numbers = @(1,2,3,4,5)
438+
}
439+
# Try to expand multiple properties using a wildcard.
440+
$object | Select-Object -ExpandProperty N*
441+
Select-Object: Multiple properties cannot be expanded.
442+
443+
# Use a wildcard that resolves to a single property.
444+
$object | Select-Object -ExpandProperty Na*
445+
John
446+
Jane
447+
Joe
448+
```
449+
447450
## PARAMETERS
448451

449452
### -CaseInsensitive
@@ -488,17 +491,19 @@ Accept wildcard characters: True
488491
489492
Specifies a property to select, and indicates that an attempt should be made to expand that
490493
property. If the input object pipeline doesn't have the property named, `Select-Object` returns an
491-
error.
494+
error. This parameter supports wildcards. However, the wildcard character must resolve to a single
495+
property name. If the wildcard character resolves to more than one property name, `Select-Object`
496+
returns an error.
497+
498+
When you use **ExpandProperty**, `Select-Object` attempts to expand the specified property for every
492499

493500
- If the specified property is an array, each value of the array is included in the output.
494501
- If the specified property is an object, the objects properties are expanded for every
495502
**InputObject**
496503

497-
In either case, the output objects' **Type** matches the expanded property's **Type**.
498-
499-
> [!NOTE]
500-
> There is a side-effect when using **ExpandProperty**. The `Select-Object` adds the selected
501-
> properties to the original object as **NoteProperty** members.
504+
In either case, the output objects' **Type** matches the expanded property's **Type**. There is a
505+
side-effect when using **ExpandProperty**. The `Select-Object` adds the selected properties to the
506+
original object as **NoteProperty** members.
502507

503508
If the **Property** parameter is specified, `Select-Object` attempts to add each selected property
504509
as a **NoteProperty** to every outputted object.
@@ -521,7 +526,7 @@ Required: False
521526
Position: Named
522527
Default value: None
523528
Accept pipeline input: False
524-
Accept wildcard characters: False
529+
Accept wildcard characters: True
525530
```
526531

527532
### -First

0 commit comments

Comments
 (0)