0

I have a strange behavior when I try to count how much drivers are connected to a workstation.

PS C:\WINDOWS> get-disk | select number, size

number          size
------          ----
 0  512110190592
 1 1000204886016

PS C:\WINDOWS> (get-disk | select number, size).count
2

So far, so good. Now, I'm going to filter it down to select my smallest drive

PS C:\WINDOWS> get-disk | Where-Object { $_.Size -lt 600GB } | select number, size

number         size
------         ----
 0 512110190592

PS C:\WINDOWS> (get-disk | Where-Object { $_.Size -lt 600GB } | select number, size).count

Where is my count? Shouldn't it return 1? It is working fine with other collections of one:

PS C:\WINDOWS> (get-process).count
196

PS C:\WINDOWS> (get-process powershell_ise ).count
1

Is it an issue with my disks object type?

PS C:\WINDOWS> Get-Disk |gm

TypeName: Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_Disk

Much confusion in my brain now!

Anyone has an idea what could go wrong there?

1 Answer 1

2

This did the trick for me:

(get-disk | Where-Object { $_.Size -lt 600GB }).Number.Count

This:

(get-disk | Where-Object { $_.Size -lt 600GB })

Is of type CimInstance and apparently it doesn't support Count

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately it is the same, the select is just for the example to make output easier to read here. My script doesn't actually filter anything. I have a workaround by creating a custom PSobject, and it is working fine. I'm mostly wondering why this is not working out of the box.
It does work fine when I look at a property. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.