Created
July 19, 2022 21:35
-
-
Save webtroter/57cf898029a31d0db2662e12c8ebce43 to your computer and use it in GitHub Desktop.
PowerShell Profile Sections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CustomHistoryHandler = { | |
param([string]$line) | |
$AllowListRegex = @( # Add keywords to match that you want to allow in your history file. | |
"Get-TokenFromOutlook" | |
) -join '|' | |
$DenyListRegex = @( # Add keywords to match that you don't want in your history file | |
"correcthorsebatterystaple" | |
) -join '|' | |
switch ($line) { | |
{ $_ -match $AllowListRegex } { [Microsoft.PowerShell.AddToHistoryOption]::MemoryAndFile } | |
{ $_ -match $DenyListRegex } { [Microsoft.PowerShell.AddToHistoryOption]::MemoryOnly } | |
Default { [Microsoft.PowerShell.PSConsoleReadLine]::GetDefaultAddToHistoryOption($_) } # Default falls back to the default handler function | |
} | |
} | |
Set-PSReadLineOption -AddToHistoryHandler $CustomHistoryHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment