Title: Get-Command: Returned CommandInfo object does not populate ScriptBlock property when -Name parameter is not used · Issue #8910 · PowerShell/PowerShell · GitHub
Open Graph Title: Get-Command: Returned CommandInfo object does not populate ScriptBlock property when -Name parameter is not used · Issue #8910 · PowerShell/PowerShell
X Title: Get-Command: Returned CommandInfo object does not populate ScriptBlock property when -Name parameter is not used · Issue #8910 · PowerShell/PowerShell
Description: Steps to reproduce I created a Pester test for this Describe "My test" { It "works" { (Get-Command -CommandType Function | Where-Object { $_.Name -eq 'Install-Module' }).ScriptBlock.Attributes | Should -Not -BeNullOrEmpty (Get-Command 'I...
Open Graph Description: Steps to reproduce I created a Pester test for this Describe "My test" { It "works" { (Get-Command -CommandType Function | Where-Object { $_.Name -eq 'Install-Module' }).ScriptBlock.Attributes | Sh...
X Description: Steps to reproduce I created a Pester test for this Describe "My test" { It "works" { (Get-Command -CommandType Function | Where-Object { $_.Name -eq 'Install-Module' })...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/8910
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Get-Command: Returned CommandInfo object does not populate ScriptBlock property when -Name parameter is not used","articleBody":"# Steps to reproduce\r\nI created a Pester test for this\r\n```powershell\r\nDescribe \"My test\" {\r\n It \"works\" {\r\n (Get-Command -CommandType Function | Where-Object { $_.Name -eq 'Install-Module' }).ScriptBlock.Attributes | Should -Not -BeNullOrEmpty\r\n (Get-Command 'Install-Module').ScriptBlock.Attributes | Should -Not -BeNullOrEmpty \r\n }\r\n}\r\n```\r\n\r\n# Expected behavior\r\n\r\nThe test passes.\r\n\r\n# Actual behavior\r\n\r\n```none\r\n Describing My test\r\n [-] works 84ms\r\n Expected a value, but got $null or empty.\r\n 3: (Get-Command -CommandType Function | Where-Object { $_.Name -eq 'Install-Module' }).ScriptBlock.Attributes | Should -Not -BeNullOrEmpty\r\n at \u003cScriptBlock>, C:\\Users\\cberg\\Desktop\\foo.tests.ps1: line 3\r\n```\r\n\r\nThe test passed only once `Get-Command 'Install-Module'` gets executed once in the current session.\r\nI acknowledge that `Get-Command` tries to be more efficient when returning all commands but at least when accessing the properties of the object I'd expect them to be lazily evaluated.\r\nBackground: In order to improve performance of PSSA, I would like to run `Get-Command` in the background once to populate a cached version of the commands instead of individually calling `Get-Command -Name` for each command, which is much more expensive.\r\n\r\n# Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```none\r\n\r\nName Value\r\n---- -----\r\nPSVersion 6.2.0-preview.4\r\nPSEdition Core\r\nGitCommitId 6.2.0-preview.4\r\nOS Microsoft Windows 10.0.17763\r\nPlatform Win32NT\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","author":{"url":"https://github.com/bergmeister","@type":"Person","name":"bergmeister"},"datePublished":"2019-02-18T18:37:43Z","url":"https://github.com/PowerShell/PowerShell/issues/8910"}
| 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:25d58621-9cc3-d3ad-0ba9-49cba6c05891 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 976A:3FD364:3BF22C:4F9B90:6AFCE8EE |
| html-safe-nonce | 920b9066ecbef7a616b1eb9b9bde8e9138030074fcdde74d900641a7f8a8be37 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzZBOjNGRDM2NDozQkYyMkM6NEY5QjkwOjZBRkNFOEVFIiwidmlzaXRvcl9pZCI6IjMyMjU5NzQyMzg3NDU1MjAzNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9616cc1d8bff0874e226f551516d7c4e9684cbb7113c84c29635800afd233873 |
| hovercard-subject-tag | issue:411602546 |
| 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/PowerShell/8910/issue_layout |
| twitter:image | https://opengraph.githubassets.com/52e95ab9f48103893b70cc3b6d6f0c788f0d6fdb068b242ccdeee116d8630d92/PowerShell/PowerShell/issues/8910 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/52e95ab9f48103893b70cc3b6d6f0c788f0d6fdb068b242ccdeee116d8630d92/PowerShell/PowerShell/issues/8910 |
| og:image:alt | Steps to reproduce I created a Pester test for this Describe "My test" { It "works" { (Get-Command -CommandType Function | Where-Object { $_.Name -eq 'Install-Module' }).ScriptBlock.Attributes | Sh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bergmeister |
| hostname | github.com |
| expected-hostname | github.com |
| None | 99aede4c5f55ec5cf06666a8c9e03ebf9f85f7231223e7f1c38c16e5504835b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width