header image

Getting unique values

Posted by: | February 4, 2012 | No Comment |

A question came up on the forum about getting the list of unique verbs in the cmdlets on their system.  This is a good example of finding unique values.

On my system

(Get-Command -Verb get ).count

returns 49 – but I only want the verb “get” to feature once

Two quick snippets to solve this.

If you want a list of unique values

Get-Command |
select -Unique verb

If you just want a count

Get-Command |
sort -Unique verb |

Both sort and select have a unique parameter

There should be a sort in the first statement for most objects – but Get-Command outputs sorted by verb so didn’t need it here

under: PowerShell Basics