kpollock
kpollock

Reputation: 3989

Powershell 5.0 / ISE

I have an example code snippet that suggests using

(Get-Process | Where-Object {$_.WorkingSet64 -gt 20mb}).Count

to return the count of all processess using > 20Mb.

It works, but when typing, neither Intellisense or the "Tab" key shows this property, rather they show the properties of an individual process - which I find misleading.

I understand, that specifying an item property will give me the list of that property only, but is there a way to easily see, in general, what ALL the valid propeties are, including list aggregates etc?

Even assigning to a variable

$processes = Get-Process | Where-Object {$_.WorkingSet64 -gt 20mb}

does not show me "Count" as a valid property of $processes until AFTER the assignment has been actually run and the value assigned - when writing the script it still shows the properties for an individual item.

For me, Intellisense / Tab help that does not cover all the options kind of defeats the purpose ... (not having to remember hundreds objects/functions and their properties / parameters).

Is there any way to improve this situation? Some syntax trick have I missed?

Upvotes: 2

Views: 68

Answers (2)

kpollock
kpollock

Reputation: 3989

Using @() to force an array type is handy when that is what is wanted.

e.g. $processes = @(Get-Process | Where-Object {$_.WorkingSet64 -gt 20mb}). will show you "Count" and the other array properties.

Other than that, let's say the Intellisense has various limitations / shortcomings that I will just have to learn... sigh.

Upvotes: 2

Mark Wragg
Mark Wragg

Reputation: 23355

The correct way to find out all of the properties of an object is to pipe the output to Get-Member:

Get-Process | Get-Member

Sometimes there are hidden properties and methods that can only be seen if you add the -force switch:

Get-Process | Get-Member -Force

The count property is an automatic property that is always usable on any collection object but that isn't explicitly listed as a property. Another example of an automatic property is length.

Upvotes: 2

Related Questions