Select-Object -Exclude not working as expected

Hello

 

If I do 

 

get-service | select -ExcludeProperty  Status

 

it still returns the status field, anyone now why? basically -Exclude does not seem to do anything

Any help most welcome

__AUser

  • Get-help for select-object says:

    -ExcludeProperty <String[]>

    Specifies the properties that this cmdlet excludes from the operation. Wildcards are permitted. This parameter is effective only when the command also includes the Property parameter.

    That seems a bit silly on the surface of it since you could simply say "-property prop1, prop2 ..." and just leave out status. At any rate, that's why it isn't working as you expect.

  • In reply to cmartin16:

    Thanks cmartin16

    got it now

    get-service | select -property name,displayname,status -exclude status

    weird but as least it works

    Thanks
    __AUser
  • In reply to Auser:

    Actually I also realise now you can do

    get-service | select -property name,displayname,status -exclude status,name

    e.g. exclude more than one property, and

    get-service | select -property * -exclude status,name

    work too

    thanks again for your help Cmartin