Title: Function-Based Custom Rule with "Error" Severity Doesn’t Show Under -Severity Error · Issue #2049 · PowerShell/PSScriptAnalyzer · GitHub
Open Graph Title: Function-Based Custom Rule with "Error" Severity Doesn’t Show Under -Severity Error · Issue #2049 · PowerShell/PSScriptAnalyzer
X Title: Function-Based Custom Rule with "Error" Severity Doesn’t Show Under -Severity Error · Issue #2049 · PowerShell/PSScriptAnalyzer
Description: I'm experiencing an issue with function-based custom rules. When a custom rule returns a severity of Error, the results don't appear under the -Severity Error filter. Instead, they show up only when filtering by warnings or when no filte...
Open Graph Description: I'm experiencing an issue with function-based custom rules. When a custom rule returns a severity of Error, the results don't appear under the -Severity Error filter. Instead, they show up only whe...
X Description: I'm experiencing an issue with function-based custom rules. When a custom rule returns a severity of Error, the results don't appear under the -Severity Error filter. Instead, they show up ...
Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/issues/2049
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function-Based Custom Rule with \"Error\" Severity Doesn’t Show Under -Severity Error","articleBody":"I'm experiencing an issue with function-based custom rules. When a custom rule returns a severity of `Error`, the results don't appear under the `-Severity Error` filter. Instead, they show up only when filtering by warnings or when no filter is applied.\r\n\r\nI couldn’t find any other reports of a similar issue. The closest I came across was [#1237](https://github.com/PowerShell/PSScriptAnalyzer/issues/1237), but it seems unanswered or possibly overlooked.\r\n\r\nThe use-case here is for demonstration purposes.\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\nCustom Rule (Measure-AvoidCustomInvokeExpression.psm1)\r\n```PowerShell\r\nfunction Measure-AvoidCustomInvokeExpression {\r\n [CmdletBinding()]\r\n [OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]\r\n param (\r\n [Parameter(Mandatory = $true)]\r\n [ValidateNotNullOrEmpty()]\r\n [System.Management.Automation.Language.ScriptBlockAst] $ScriptBlockAst\r\n )\r\n process {\r\n $results = @()\r\n \r\n try {\r\n [ScriptBlock]$predicate = {\r\n param (\r\n [System.Management.Automation.Language.Ast] $Ast\r\n )\r\n [bool]$returnValue = $false\r\n \r\n if ($Ast -is [System.Management.Automation.Language.CommandAst]) {\r\n [System.Management.Automation.Language.CommandAst]$commandAst = $Ast\r\n if ($commandAst.GetCommandName() -eq 'Invoke-Expression') {\r\n $returnValue = $true\r\n }\r\n }\r\n return $returnValue\r\n }\r\n \r\n [System.Management.Automation.Language.Ast[]]$asts = $ScriptBlockAst.FindAll($predicate, $true)\r\n if ($asts.Count -ne 0) {\r\n foreach ($ast in $asts) {\r\n $result = New-Object `\r\n -TypeName \"Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord\" `\r\n -ArgumentList `\r\n \"Stop it!\", \r\n $ast.Extent, \r\n \"AvoidCustomInvokeExpression\", \r\n Error, \r\n $null\r\n \r\n $results += $result\r\n }\r\n }\r\n return $results\r\n }\r\n catch {\r\n $PSCmdlet.ThrowTerminatingError($PSItem)\r\n }\r\n }\r\n}\r\n\r\nExport-ModuleMember -Function Measure-AvoidCustomInvokeExpression\r\n```\r\n\r\nTest Script (Invoke-GetProcess.ps1)\r\n```powershell\r\nInvoke-Expression \"Get-Process\"\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n```none\r\nInvoke-ScriptAnalyzer -Path ./Invoke-GetProcess.ps1 -CustomRulePath ./Measure-AvoidCustomInvokeExpression.psm1 -Severity Error\r\n\r\nRuleName Severity ScriptName Line Message\r\n-------- -------- ---------- ---- -------\r\nCustom Name Error Invoke-Get 1 Stop it!\r\n Process.ps\r\n 1\r\n```\r\n\r\nActual behavior\r\n---------------\r\nUsed with `-Severity Error`\r\n```none\r\nInvoke-ScriptAnalyzer -Path ./Invoke-GetProcess.ps1 -CustomRulePath ./Measure-AvoidCustomInvokeExpression.psm1 -Severity Error\r\n\r\n\u003cnothing>\r\n```\r\n\r\nUsed with `-Severity Warning`\r\n```none\r\nInvoke-ScriptAnalyzer -Path ./Invoke-GetProcess.ps1 -CustomRulePath ./Measure-AvoidCustomInvokeExpression.psm1 -Severity Warning\r\n\r\nRuleName Severity ScriptName Line Message\r\n-------- -------- ---------- ---- -------\r\nCustom Name Error Invoke-Get 1 Stop it!\r\n Process.ps\r\n 1\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- Provide the output of the following 2 commands -->\r\n\r\nWindows 11\r\n```PowerShell\r\n> $PSVersionTable\r\nPSVersion 5.1.22621.4391\r\nPSEdition Desktop\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nBuildVersion 10.0.22621.4391\r\nCLRVersion 4.0.30319.42000\r\nWSManStackVersion 3.0\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\n\r\n> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }\r\n1.23.0\r\n```\r\n\r\nManjaro 6.6.63-1\r\n```Powershell\r\n> $PSVersionTable\r\nPSVersion 7.4.1\r\nPSEdition Core\r\nGitCommitId 7.4.1-0-g5668713d3c906d63cd68e37d415206a95ac061d0\r\nOS Manjaro Linux\r\nPlatform Unix\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n\r\n> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }\r\n1.23.0\r\n```\r\n","author":{"url":"https://github.com/Geevo","@type":"Person","name":"Geevo"},"datePublished":"2024-12-16T14:05:24Z","url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/2049"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d114fbe0-9536-8bf4-bb82-aaaa5d993d35 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BC22:E9A8B:14132EA:1C616C8:6AFCE47A |
| html-safe-nonce | 2d585f0a83e544df58308277dead44149f31b26ab025be7a6bee25aeeca46eb5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzIyOkU5QThCOjE0MTMyRUE6MUM2MTZDODo2QUZDRTQ3QSIsInZpc2l0b3JfaWQiOiI2NjQ5NzY3MzM3ODQwNjY1NzIyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a42ec50f016daf1108ada6a887df8692fb80f0a664a9d805ca496a08c07ab07a |
| hovercard-subject-tag | issue:2742486046 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PSScriptAnalyzer/2049/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e42d08c367317604e52572ce27884bf3df2fc29312fd69d4ca2b50aba2f3cba4/PowerShell/PSScriptAnalyzer/issues/2049 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e42d08c367317604e52572ce27884bf3df2fc29312fd69d4ca2b50aba2f3cba4/PowerShell/PSScriptAnalyzer/issues/2049 |
| og:image:alt | I'm experiencing an issue with function-based custom rules. When a custom rule returns a severity of Error, the results don't appear under the -Severity Error filter. Instead, they show up only whe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Geevo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 99aede4c5f55ec5cf06666a8c9e03ebf9f85f7231223e7f1c38c16e5504835b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PSScriptAnalyzer git https://github.com/PowerShell/PSScriptAnalyzer.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 33149177 |
| octolytics-dimension-repository_nwo | PowerShell/PSScriptAnalyzer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33149177 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PSScriptAnalyzer |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ecfd63ca125ec74b42f74eeb158b3fa081c8c497 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width