#PSTip Get the count of items in an enumeration

Note: This tip requires PowerShell 2.0 or above.

I recently got a couple of Blink(1)s and started exploring how I can use them in PowerShell. If I have to describe blink(1) in a single line, it is a USB LED that responds to programmed events by blinking in whatever color we specify.

While working with this, I was exploring how I can use the [System.Drawing.KnownColor] enumeration. So, one of the items on my list was to find the count of items in this enumeration.

So, this is how I did that:

Add-Type -AssemblyName System.Drawing

In the next tip, I will show how I used this count value to retrieve a random item from the enumeration.

Share on: