Skip to content

Instantly share code, notes, and snippets.

@Sarafian
Last active August 24, 2016 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sarafian/5f86413001c7c72f56537defaa2af4c1 to your computer and use it in GitHub Desktop.
Save Sarafian/5f86413001c7c72f56537defaa2af4c1 to your computer and use it in GitHub Desktop.
Toggle Debug and Verbose preference in PowerShell with shortcut keys. Add the script to your Microsoft.PowerShell_profile.ps1
Set-PSReadlineKeyHandler -Chord "Ctrl+1" -BriefDescription 'Toggle $DebugPreference' -Description 'Toggle $DebugPreference between Continue and SilentlyContiinue' -ScriptBlock {
if($DebugPreference -eq 'Continue')
{
Write-Debug "Setting DebugPreference=SilentlyContinue"
Set-Variable -Name DebugPreference -Value "SilentlyContinue" -Scope Global -Force
return
}
if($DebugPreference -eq 'SilentlyContinue')
{
Set-Variable -Name DebugPreference -Value "Continue" -Scope Global -Force
Write-Debug "Setting DebugPreference=$DebugPreference"
return
}
}
Set-PSReadlineKeyHandler -Chord "Ctrl+2" -BriefDescription 'Toggle $VerbosePreference' -Description 'Toggle $VerbosePreference between Continue and SilentlyContiinue' -ScriptBlock {
if($VerbosePreference -eq 'Continue')
{
Write-Verbose "Setting VerbosePreference=SilentlyContinue"
Set-Variable -Name VerbosePreference -Value "SilentlyContinue" -Scope Global -Force
return
}
if($VerbosePreference -eq 'SilentlyContinue')
{
Set-Variable -Name VerbosePreference -Value "Continue" -Scope Global -Force
Write-Verbose "Setting VerbosePreference=$VerbosePreference"
return
}
}
Set-PSReadlineKeyHandler -Chord "Ctrl+3" -BriefDescription 'Toggle $InformationPreference' -Description 'Toggle $InformationPreference between Continue and SilentlyContiinue' -ScriptBlock {
if($InformationPreference -eq 'Continue')
{
Write-Information "Setting InformationPreference=SilentlyContinue"
Set-Variable -Name InformationPreference -Value "SilentlyContinue" -Scope Global -Force
return
}
if($InformationPreference -eq 'SilentlyContinue')
{
Set-Variable -Name InformationPreference -Value "Continue" -Scope Global -Force
Write-Information "Setting InformationPreference=$InformationPreference"
return
}
}
Get-PSReadlineKeyHandler |Where-Object -Property Function -Like "Toggle*" |ForEach-Object {
"$($_.Key): $($_.Description)"
}
@Sarafian
Copy link
Author

Add the script to your Microsoft.PowerShell_profile.ps1.
This is doesn't work with PowerShell ISE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment