0

I am using the PSScriptAnalyzer static code checker. When I run this example commnad Invoke-ScriptAnalyzer -Path .\MySuperLongLongFileName.ps1 -Settings PSGallery the code checker logs are presented in a table format. This format causes the script name and message information to overflow into the lines below it.

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseSingularNouns                  Warning      My-Function 53    The cmdlet 'My-Function' uses a plural n
                                                 MySuper           oun. A singular noun should be used instead.
                                                 LongLong
                                                 FileName.
                                                 ps1
PSUseSingularNouns                  Warning      My-Function 84    The cmdlet 'My-Function' uses a plur
                                                 MySuper           al noun. A singular noun should be used instead.
                                                 LongLong
                                                 FileName.
                                                 ps1


Ideally I want to format the output like this, so that I can parse it line by line and read the errors into any array. Any suggestions?

RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseSingularNouns Warning My-Function 53 MySuperLongLongFileName.ps1 The cmdlet 'My-Function' uses a plural noun. A singular noun should be used instead.
PSUseSingularNouns Warning My-Function 84 MySuperLongLongFileName.ps1 The cmdlet 'My-Function' uses a plural noun. A singular noun should be used instead.

Also raised this question on the PowerShell/PSScriptAnalyzer GitHub forum.

greg
  • 1,118
  • 1
  • 20
  • 40
  • 3
    There is no need to parse anything, as `Invoke-ScriptAnalyzer` already outputs objects. To read the output into an array just do `$myArray = Invoke-ScriptAnalyzer -Path .\MySuperLongLongFileName.ps1 -Settings PSGallery`. Then to access a property do e. g. `$myArray[2].Message`. To show all messages only: `$myArray.Message` – zett42 Nov 14 '22 at 17:24

0 Answers0