Title: Cmdlets that run in current scope (like ForEach-Object) not accounted for by PSUseDeclaredVarsMoreThanAssignments · Issue #1163 · PowerShell/PSScriptAnalyzer · GitHub
Open Graph Title: Cmdlets that run in current scope (like ForEach-Object) not accounted for by PSUseDeclaredVarsMoreThanAssignments · Issue #1163 · PowerShell/PSScriptAnalyzer
X Title: Cmdlets that run in current scope (like ForEach-Object) not accounted for by PSUseDeclaredVarsMoreThanAssignments · Issue #1163 · PowerShell/PSScriptAnalyzer
Description: Although issue #1031 and #1129 probably have the same cause, I have added a new bug report as it is (afaik) not directly related to the Begin, Process and End function blocks as suggested in there which brings the issue in a different pe...
Open Graph Description: Although issue #1031 and #1129 probably have the same cause, I have added a new bug report as it is (afaik) not directly related to the Begin, Process and End function blocks as suggested in there ...
X Description: Although issue #1031 and #1129 probably have the same cause, I have added a new bug report as it is (afaik) not directly related to the Begin, Process and End function blocks as suggested in there ...
Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/issues/1163
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cmdlets that run in current scope (like ForEach-Object) not accounted for by PSUseDeclaredVarsMoreThanAssignments","articleBody":"Although issue #1031 and #1129 probably have the same cause, I have added a new bug report as it is (afaik) not directly related to the `Begin`, `Process` and `End` function blocks as suggested in there which brings the issue in a different perspective.\r\n\r\nApparently for some cmdlets, PowerShell [is invoked in the current scope](https://www.powershellmagazine.com/2014/10/22/foreach-and-where-magic-methods/) but that is apparently *not* respected by the PSScriptAnalyzer.\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```PowerShell\r\n$Test = $False\r\n1..3 | ForEach-Object {$Test = $True}\r\n$Test\r\n```\r\nnote that the result of the above is `$True`, meaning that the value of `$Test` is actually assigned and changed to `$True` within the `ForEach-Object` cmdlet.\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nNo warning.\r\n\r\nActual behavior\r\n---------------\r\n\r\n```none\r\nRuleName Severity ScriptName Line Message\r\n-------- -------- ---------- ---- -------\r\nPSUseDeclaredVarsMoreThanAssignment Warning Test.ps1 2 The variable 'Test' is assigned but never used.\r\n```\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\n```PowerShell\r\nName Value\r\n---- -----\r\nPSVersion 5.1.17134.590\r\nPSEdition Desktop\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nBuildVersion 10.0.17134.590\r\nCLRVersion 4.0.30319.42000\r\nWSManStackVersion 3.0\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\n\r\nPSScriptAnalyzer.Version: 1.17.1\r\n\r\n```\r\n\r\nWill this eventually be resolved?\r\nHow can I nicely avoid the incorrect warning in an example like above?","author":{"url":"https://github.com/iRon7","@type":"Person","name":"iRon7"},"datePublished":"2019-03-04T08:25:15Z","url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/1163"}
| 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:757d1dc9-a29c-d935-9eb5-44b9a4bc8000 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B4DC:2ED338:1406CE:1A3869:6AFCFE44 |
| html-safe-nonce | 65e4d19a71616ca0bc5d15f689f3ba6c048457363cc42f44c69079782b50d39d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNERDOjJFRDMzODoxNDA2Q0U6MUEzODY5OjZBRkNGRTQ0IiwidmlzaXRvcl9pZCI6IjU1MzU3Nzc5MjkzNjA2Mzc1MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 54bd28f3d3df4082acf20435921847a10a931dea02271e6e2d9a0ddccbea0f84 |
| hovercard-subject-tag | issue:416683583 |
| 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/1163/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c52a006ebaff79118d798d1496b73b15c0ab8b6c74309b3627f5ec5c9e70465e/PowerShell/PSScriptAnalyzer/issues/1163 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c52a006ebaff79118d798d1496b73b15c0ab8b6c74309b3627f5ec5c9e70465e/PowerShell/PSScriptAnalyzer/issues/1163 |
| og:image:alt | Although issue #1031 and #1129 probably have the same cause, I have added a new bug report as it is (afaik) not directly related to the Begin, Process and End function blocks as suggested in there ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iRon7 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cfabad6ee26d2b84c7afef4ae0cc71b8b692fb9d66f9f15997652ef991bfd3f4 |
| 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 | 35f85b78676038389558a41adf8d76e474592ede |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width