PowerTip: Eliminate Duplicates in PowerShell History


Summary: Use an option in the PSReadLine module to control Windows PowerShell 5.0 history duplication.

Hey, Scripting Guy! Question How can I make sure that there are no duplicates in my history?

Hey, Scripting Guy! Answer In Windows PowerShell 5.0 with the PSReadLineModule loaded, use the Set-PSReadLineOption 
           cmdlet as follows:

Set-PSReadLineOption –HistoryNoDuplicates:$True

Comments (2)

  1. Me says:

    You can also use;
    get-history | select -unique
    to eliminate duplicate entries

  2. Stefan says:

    Note that the – in the string in the answer above isn’t a – but a –. Be careful if you cut and paste that string to your profile – it will cause you grief.

Skip to main content