Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Last active July 9, 2021 09:51
Show Gist options
  • Save PrateekKumarSingh/df9b0b0697c1b9a1e2416afa7d22f7b2 to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/df9b0b0697c1b9a1e2416afa7d22f7b2 to your computer and use it in GitHub Desktop.
Function Get-Comment
{
Param([Parameter(Position=0)] [String] $FilePath,[Switch] $FromClipBoard)
If($FilePath)
{
$Content = Get-Content $FilePath
}
elseif($FromClipBoard)
{
$Content = [Windows.clipboard]::GetText()
}
else
{
Write-Host "Please provide a file/content to look for comments."
}
$CommentTokens = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$null) | `
Where-Object{$_.type -like "*comment*"}
Foreach($obj in $CommentTokens)
{
$IndentSpace = ""
If($obj.StartColumn -gt 1)
{
1..($obj.startcolumn - 1)| %{[String]$IndentSpace += " "}
#$IndentSpace+$obj.content
}
''| select @{n='Line';e={$obj.StartLine}}, @{n="Comment";e={$IndentSpace+$obj.Content}}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment