Skip to content

Instantly share code, notes, and snippets.

@webtroter
Created July 19, 2022 21:35
Show Gist options
  • Save webtroter/57cf898029a31d0db2662e12c8ebce43 to your computer and use it in GitHub Desktop.
Save webtroter/57cf898029a31d0db2662e12c8ebce43 to your computer and use it in GitHub Desktop.
PowerShell Profile Sections
$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