Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Created November 29, 2023 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaykul/dd1c341da90e47396f6f523031000221 to your computer and use it in GitHub Desktop.
Save Jaykul/dd1c341da90e47396f6f523031000221 to your computer and use it in GitHub Desktop.
Let's have a look at what commands we use
[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
@Jaykul
Copy link
Author

Jaykul commented Nov 29, 2023

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment