Hello Reader!
To Review and understand scripts written by another developer, I often find Comments helpful.
PURPOSE
I was looking for a way through which we can extract all comments. Just to get a skeleton view of script’s functionalities documented by the programmer. Saves me some time!
So today’s tip is about extracting all comments from a Powershell script, and it supports following items –
- Comment extraction from a File
- Comment extraction from a script copied to clipboard
- [Updated] Includes Line number of the comment
- [Updated] Output matches the comment Indentation in the Powershell script
APPROACH
- Get the content of the file and Tokenize it.
- Filter out comments only from all Powershell tokens.
- [Updated] Identify the Line number and Column position (Indentation) of each comment token
- [Updated] Add spaces to the output in order to match script indentation.
And a Small animation showing how it runs.
There could be more ways to do that like below, but I Personally trust the Parser more 🙂
Hope you find the Powershell tips useful!
Author of “PowerShell Guide to Python“, “Windows Subsystem for Linux (WSL)” and currently writing the most awaited book: “PowerShell to C# and Back” !
Prateek Singh
Engineer. Blogger. Science and Technology fan.
Ridiculously Curious and a compulsive Book reader.
Related posts
0 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,872 People Reached
[…] on June 28, 2016 submitted by /u/Prateeksingh1590 [link] [comments] Leave a […]
[…] in a script: Following is a link to my one of my old blog posts where I used Tokenization to extract comments from PowerShell script […]
[…] in a script: Following is a link to my one of my old blog posts where I used Tokenization to extract comments from PowerShell script […]
[…] in a script: Following is a link to my one of my old blog posts where I used Tokenization to extract comments from PowerShell script […]