In the previous tip we looked at command extensions for the good old PowerShell ISE. Here is another sample that adds the CTRL+K keyboard shortcut to append comments (“#”) to each selected line:
function Invoke-Comment { $file = $psise.CurrentFile $comment = ($file.Editor.SelectedText -split '\n' | ForEach-Object { "#$_" }) -join "`n" $file.Editor.InsertText($comment) } $psise.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Comment Out', { Invoke-Comment }, 'CTRL+K')