Last active
August 24, 2016 09:21
-
-
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
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
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)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add the script to your
Microsoft.PowerShell_profile.ps1
.This is doesn't work with PowerShell ISE.