In Powershell Ver 3.0 and above you can comment and un-comment multiple lines in one go, using the below trick.
Suppose you have a code and you want to comment all the lines of code starting from Line1 – Line12 like in the below example, obviously you can use Block commenting instead, In which you can comment your code inside comment blocks <# Your Code #>,
But I’ve a quicker way for you, that can be prove productive in day-to-day scripting
Just press ALT + SHIFT at the first line and use the UP/DOWN Arrow key to navigate to the bottom line just like in the images.
Drag the cursor till the last line
and more
and more until, you see a straight line like the picture below.
When you are at the last line just press ‘SHIFT + #’ to add Pound(‘#’) in front of each line, making them all comments.
And, to uncomment any such block you can simply follow the same steps and press delete or backspace to remove the ‘#’. Quick and Easy !! 😀
Hope you will like this trick, Happy Learning 🙂
~ Courtesy http://www.dexterposh.com/
Prateek Singh
Related posts
10 Comments
Leave a ReplyCancel reply
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,132,192 People Reached
Thanks for the mention and keep sharing the #PowerShell love 😉
Was worth mentioning 🙂 Cheers.!
nice
[…] Read the complete article on my new website RidiCurious.com […]
This is great help in in reducing typing and increasing productivity.
Thank you for sharing, this is an immense help!!
why not
Thanks. A useful tip, but I think the following from one from Microsoft is better: https://devblogs.microsoft.com/scripting/powertip-use-powershell-multiple-line-comments/
It depends on the task – sometimes I use a lot of single-line comments and want to uncomment just one line (like 40 different script-lines which I use depending on the task) and then the Alt-Shift-Way is better in this situation.
For Script-Headers and descriptive comments I use the mulitline-comment <# – Way
Fantastic! simple and effective.