Last active
January 17, 2017 11:34
-
-
Save markwragg/be3b3c047401dff11c2050e3afb16920 to your computer and use it in GitHub Desktop.
Powershell command to see the max min and average length of cmdlets. Decided to do this after seeing how crazy long Get-WinAcceptLanguageFromLanguageListOptOut is as a cmdlet and wondering if it was the longest. Also used this to experiment with calculated properties and discovered you can use them in sort and select as well as where.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Get stats on length of the cmdlet name such as max, min, average, sum | |
| Get-Command | where CommandType -eq cmdlet | select -ExpandProperty name | measure length -Average -Sum -Max -Min | |
| # See the list, sorted by length | |
| Get-Command | where CommandType -eq cmdlet | select -ExpandProperty name | sort length | |
| #Another way to get this statistic using calculated properties | |
| Get-Command | where CommandType -eq cmdlet | select name,@{N='length';E={$_.name.length}} | measure length -Average -Sum -Max -Min | |
| # See the list this way, sorted by length (we can skip the select and use the expression in sort) | |
| Get-Command | where CommandType -eq cmdlet | sort @{E={$_.name.length}} | |
| # You can't seem to use calculated expressions in measure-object so we seemingly can't do: | |
| # Get-Command | where CommandType -eq cmdlet | measure @{E={$_.name.length}} -Average -Sum -Max -Min | |
| #Calculated expressions can be used in the format- commands also, for example: | |
| Get-CimInstance -ClassName Win32_LogicalDisk | where deviceid -eq "C:" | format-table deviceid,@{n='freespace (GB)';e={$_.freespace / 1GB};formatstring='N2'},size,@{n='description';e={$_.description};width=10} | |
| #Format-table has a groupby param. Starts a new group every time the property changes, so may be wise to sort first. | |
| Get-Service | Sort Status | Format-Table -GroupBy Status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment