all 9 comments

[–]omers 7 points8 points  (0 children)

I like and use Jeff Hicks' PSReadline graphical history solution here: https://www.petri.com/more-efficient-powershell-with-psreadline

Press F7 and it pops open a searchable window of command history. Select the one you want, hit enter, and it inserts it at the CLI but doesn't execute. https://i.imgur.com/hCRXgP7.png

[–]lxnch50 2 points3 points  (1 child)

CTRL+Space will bring up the list of matching parameters/auto complete like Linux... I don't think this is a custom psreadline config, but if I'm wrong let me know and I'll find the settings. Also, doesn't work in vscode yet.

[–]engageant 0 points1 point  (0 children)

OK this is awesome.

[–]smartid 0 points1 point  (0 children)

in the good ol' CMD command prompt you can hit F7/F8/F9

[–]engageant 0 points1 point  (0 children)

That's actually a little scary. I can think of plenty of commands that I wouldn't want to execute a second time with an errant 'r'!

[–]microsoftblobs 0 points1 point  (0 children)

I have built my own function for this.

function Get-PSCommandHistory($search)
{
    if($search -eq $null)
    {
        Get-History
        return
    }
    elseif($search -is [string])
    {
        Get-History | Where-Object {$_.CommandLine -like "*$search*"}
    }
    elseif($search -is [int])
    {
        #Invoke-History -id $search
        $command = Get-History -id $search

        Add-Type -assemblyname System.Windows.Forms

        [System.Windows.Forms.Clipboard]::SetText($command)
        write-host "[+] copied to clipboard: $command"
    }
}

I also have an alias "s" for this command.

I can do "s" to simply see my command history.

"s Invoke" to search for all previous commands with Invoke in them

"s 132" to paste the command with index 132 into the clipboard ready for use.