Created
November 29, 2023 06:03
-
-
Save Jaykul/dd1c341da90e47396f6f523031000221 to your computer and use it in GitHub Desktop.
Let's have a look at what commands we use
This file contains 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
[CmdletBinding()] | |
param( | |
# Limit the number of results | |
[int]$Top | |
) | |
$Tokens = @() | |
$Names = @{} | |
foreach ($history in [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems()) { | |
$null = [System.Management.Automation.Language.Parser]::ParseInput($history.CommandLine, [ref]$Tokens, [ref]$null) | |
$Tokens.Where{ $_.TokenFlags -eq "CommandName" -and $_.Kind -in "Identifier", "Generic" }.ForEach{ | |
if ($_.Text -match "\[\]") { continue } | |
$Names[$_.Text]++ | |
} | |
} | |
$Commands = @{} | |
foreach ($kv in $Names.GetEnumerator()) { | |
$Name = $kv.Key | |
while (($command = @(Get-Command $Name -EA Ignore).Where({ $_.Name -eq $Name }, "First")[0]).CommandType -eq "Alias") { | |
$Name = $command.Definition | |
} | |
$Commands[$Name] += $kv.Value | |
} | |
$Commands.GetEnumerator() | Sort Value -Descending @PSBoundParameters |
Author
Jaykul
commented
Nov 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment