Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using the PSScriptAnalyzer static code checker. When I run this example commnad RuleNameSeverityScriptNameLineMessage-------------------------------------PSUseSingularNounsWarningMy-Function53Thecmdlet'My-Function'usesapluralnMySuperoun.Asingularnounshouldbeusedinstead.LongLongFileName.ps1PSUseSingularNounsWarningMy-Function84Thecmdlet'My-Function'usesaplurMySuperalnoun.Asingularnounshouldbeusedinstead.LongLongFileName.ps1Ideally 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? RuleNameSeverityScriptNameLineMessage-------------------------------------PSUseSingularNounsWarningMy-Function53MySuperLongLongFileName.ps1Thecmdlet'My-Function'usesapluralnoun.Asingularnounshouldbeusedinstead.PSUseSingularNounsWarningMy-Function84MySuperLongLongFileName.ps1Thecmdlet'My-Function'usesapluralnoun.Asingularnounshouldbeusedinstead.Also raised this question on the Stack Overflow. |
BetaWas this translation helpful?Give feedback.
Replies: 1 comment
-
As with most other PowerShell cmdlets, Ex: # assign output to variable$results=Invoke-ScriptAnalyzer-Path .\MySuperLongLongFileName.ps1 -Settings PSGallery # show fields we can access$results| gm TypeName: Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord Name MemberType Definition ------------------------ Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Extent Property System.Management.Automation.Language.IScriptExtent Extent{get;set} IsSuppressed Property bool IsSuppressed{get;set} Message Property string Message{get;set} RuleName Property string RuleName{get;set} RuleSuppressionID Property string RuleSuppressionID{get;set} ScriptName Property string ScriptName{get} ScriptPath Property string ScriptPath{get;set} Severity Property Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticSeverity Severity{get;set} SuggestedCorrections Property System.Collections.Generic.IEnumerable[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent] SuggestedCorrections{get;set} Column ScriptProperty System.Object Column{get=$this.Extent.StartColumnNumber} Line ScriptProperty System.Object Line{get=$this.Extent.StartLineNumber} # list RuleNames$results.RuleName# show particular diagnostic record$results[0] |
BetaWas this translation helpful?Give feedback.
As with most other PowerShell cmdlets,
Invoke-ScriptAnalyzeritself will return an object, which in this case is an array of Diagnostic Records. Assigning this output to a variable would be easier than parsing text later, as you can access the desired fields directly.Ex: