You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Get-Command: Returned CommandInfo object does not populate ScriptBlock property when -Name parameter is not used #8910
Describe "My test" {
It "works" {
(Get-Command-CommandType Function |Where-Object { $_.Name-eq'Install-Module' }).ScriptBlock.Attributes | Should -Not-BeNullOrEmpty
(Get-Command'Install-Module').ScriptBlock.Attributes | Should -Not-BeNullOrEmpty
}
}
Expected behavior
The test passes.
Actual behavior
Describing My test
[-] works 84ms
Expected a value, but got $null or empty.
3: (Get-Command -CommandType Function | Where-Object { $_.Name -eq 'Install-Module' }).ScriptBlock.Attributes | Should -Not -BeNullOrEmpty
at <ScriptBlock>, C:\Users\cberg\Desktop\foo.tests.ps1: line 3
The test passed only once Get-Command 'Install-Module' gets executed once in the current session.
I 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.
Background: 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.
Environment data
Name Value
---- -----
PSVersion 6.2.0-preview.4
PSEdition Core
GitCommitId 6.2.0-preview.4
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
changed the title [-]Get-Command: Returned CommandInfo object does not populate ScriptBlock parameter when -Name parameter is not used[/-][+]Get-Command: Returned CommandInfo object does not populate ScriptBlock property when -Name parameter is not used[/+]on Feb 18, 2019
NB: After discussing this issue with members of the PowerShell team, it seems this is not some sort of optimisation but rather a bug that we could look into fixing.
Reacted by Rain Sallow (/u/ta11ow)
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
[-]Get-Command: Returned CommandInfo object does not populate ScriptBlock parameter when -Name parameter is not used[/-][+]Get-Command: Returned CommandInfo object does not populate ScriptBlock property when -Name parameter is not used[/+]bergmeister commentedon Mar 22, 2019
NB: After discussing this issue with members of the PowerShell team, it seems this is not some sort of optimisation but rather a bug that we could look into fixing.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.