1

Get your most common PowerShell commands by inspecting your PSReadLine history

 1 year ago
source link: https://gist.github.com/devblackops/9cbfb88d426426e6a45cab724a9a2a27
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Get your most common PowerShell commands by inspecting your PSReadLine history · GitHub

Instantly share code, notes, and snippets.

Get your most common PowerShell commands by inspecting your PSReadLine history

PSParser is ancient and doesn't handle things well; use System.Management.Automation.Parser.ParseInput() instead:

$Errors = $null
$Tokens = $null
$Ast = [System.Management.Automation.Language.Parser]::ParseInput(
    ( Get-Content (Get-PSReadLineOption).HistorySavePath ),
    [ref]$Tokens,
    [ref]$Errors
)
$Tokens | 
    Where-Object { $_.TokenFlags.HasFlag([System.Management.Automation.Language.TokenFlags]::CommandName) } |
    Select-Object Text | Group-Object Text |
    Sort-Object Count, Name -Descending | Select-Object Count, Name -First 20

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK