Skip to content

Select-Object -ExcludeProperty dependency on -Property is unintuitive.  #2351

@kittholland

Description

@kittholland

Steps to reproduce

Get-Service -Name Spooler | Select-Object -ExcludeProperty Status

Expected behavior

Return a Selected.System.ServiceProcess.ServiceController object with all standard properties of System.ServiceProcess.ServiceController except Status.

Actual behavior

Returns System.ServiceProcess.ServiceController object with all properties including status.

To get the desired behavior you must use the -Property parameter in conjunction with the -ExcludeProperty parameter, this is explained in the help documentation for select-object as:

"This parameter is effective only when the command also includes the Property parameter."

I don't understand the case where you would want to declare to explicitly include a property, then exclude it again such as:

Get-Service -Name Spooler | Select-Object -Property Status -ExcludeProperty Status

Therefore the convention is to always pass "-Property *" when using the -ExcludeProperty parameter. I would suggest defaulting to -Property * when using the -ExcludeProperty cmdlet, if that would be considered a breaking change, I would suggest throwing an error if -ExcludeProperty is used without -Property indicating that you are missing a mandatory parameter since ExcludeProperty is dependent on -Property.

Environment data

> $PSVersionTable
Name                           Value                                                                                                                                                                                                                                                                                                                      
----                           -----                                                                                                                                                                                                                                                                                                                      
PSVersion                      5.0.10586.63                                                                                                                                                                                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                                                                                                                    
BuildVersion                   10.0.10586.63                                                                                                                                                                                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                                                                                                            
WSManStackVersion              3.0                                                                                                                                                                                                                                                                                                                        
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                                                                                                                        
SerializationVersion           1.1.0.1   

Metadata

Metadata

Assignees

No one assigned

    Labels

    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions