Hi again guys,
I never realised how pain-staking parsing plain text can be after the luxury of using objects for so long. Basically, I’m trying to rip out some of the comment-based help from my Powershell documents and I’m going to feed it into my Readme.md.
So, I have my .PS1 file that I’m using Get-Content on, saving to $FileContents, splitting it up via. regex and then using ‘Select-String -Pattern ‘@’ -SimpleMatch -Raw’ (I added the -Raw after reading Why Get-Content aint yer friend.
On the match results, the first line underneath .SYNOPSIS will be ‘@MyFunctionName’ so that I can tell what each comment-based help is for, but I might alter this later.
EDIT: The code sample broke formatting on the post so I’ve moved it to pastebin
I just piped it to Format-List for testing, but it looks like it’s treating my strings as a single line (even though they contain line break characters) as the returned result’s .LineNumber property returns 1.
I’ve also tried running the Select-String on the initial $FileContents variable and it seems to do the same. I’ve tried splitting my $FileContents with .Split("`n") and piping that through, but the only way I can make int work is to use
[System.IO.File]::ReadAllLines("D:\TestFile.ps1") | Select-String...
But I have to pipe it directly into my Select-String command - saving it to a variable just results in the same issue.
I had previously used .Split("`n") and looped through each line but I assumed using Select-String would be more speed efficient (and more ‘PowerShell’), but so far I can’t get it to work!