I was giving a presentation to the Austin PowerShell User Group last week and the group took notice when I quickly commented and uncommented lines in my PowerShell script in VS Code. This is very easy to do with the built in keyboard shortcuts.

How do I comment and uncomment PowerShell in Visual Studio Code and Visual Studio?

First, select the lines you want to comment out. To comment out the selected lines, press:

Ctrl+K, Ctrl+C

If you want to uncomment the selected lines, you can use the reverse keyboard shortcut:

Ctrl+K, Ctrl+U

Here’s a demo in VS Code.

Comment and Uncomment in VS Code

The same keyboard shortcuts work in Visual Studio.

How do I toggle PowerShell comments in Visual Studio Code?

You can also toggle comments using the following keyboard shortcut.

Ctrl + /

This works in Visual Studio Code but not Visual Studio.

toggle comment in VS Code

How do I toggle PowerShell block comments in Visual Studio Code?

If you wish to use a block comment in Visual Studio Code, you can use the following shortcut.

This works in Visual Studio Code but not Visual Studio.

Shift + Alt + A

Block Comment