Loading...

Easily find a specific word or command in your PowerShell history


In this post i will show you a script allowing you to search for a specific string in your PowerShel prompt history.


The issue

I'm probably sure that of lot of you have already been in the following trouble 👇

You have run a specific command one day and you try to use it again some days, months later.

You remember that you have already run it previously but you can't remind how to use it or what you have passed as parameter or something else. 


The solution

The solution there is pretty easy.

The script will search into the PowerShell history.

Indeed, when you type a command on PowerShell prompt, everything is stored locally in the file ConsoleHost_history.txt 

This one is located on the following path:

%userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine


The solution results in few steps:

1. Choose a string to search like connect-mggraph

2. Use the Search_PS1_History.ps1

3. Pass the string to search to parameter -String


Get the script

Click on the below GitHub picture to get the script


How to use the script ? 

In the following example, I want to search all command that have been executed with the string: SelfX


To search it run below command:

See below the result: 


To export result to out-gridview add parameter -OutGridview:

See below the result: 


To export result to a file add -Exportfile:

See below the result:


slider 7720241158909940207

Enregistrer un commentaire

Accueil item

Award

Learn KQL in one month

Sponsors

You want to support me ?

Mes articles en français

Books in French


Stats