Have you tried something like this?
get-command | select ModuleName | sort-object -Property ModuleName -Unique
Even shorter:
get-command | select-object moduleName -unique
Below 2 commands will bring out same result, but the first one will be sorted and a bit expensive in execution time.
The execution time will be taken more into consideration when you have large number of items, For example if you are importing csv
file of 30,000 rows. Then second option will be faster, and once you get unique values sort them if you need because here sorting will be done on a much lesser number of items hence better performance.
1.
get-command | select ModuleName | sort-object -Property ModuleName -Unique
# This will give you the execution time
Measure-Command {get-command | select ModuleName | sort-object -Property ModuleName -Unique}
2.
get-command | select ModuleName -Unique
# This will give you the execution time
Measure-Command {get-command | select ModuleName -Unique}
Another option:
Get-Command | Group-Object ModuleName -NoElement | Select-Object Name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With