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
Add more methods to directly add a CommandInfo to a PSCommand #12295
Currently PowerShell has a method that allows this, AddCommand(CommandInfo). However, there's no supported way to add a CommandInfo to a PSCommand instance directly. PowerShellEditorServices (and likely other projects) construct a PSCommand instance well before actually getting to the internal PowerShell object, so working with CommandInfo directly can only be done with reflection.
@PowerShell/powershell-committee reviewed this, the PowerShell class already exposes a method AddCommand() that takes a CommandInfo so some concerns regarding passing in a CommandInfo from one runspace into another that may be out of date is already an issue, so from that perspective, it seems there is no concern about making this public since it's already public via the PowerShell class.
TylerLeonhardtInvocationIntrinsics has a bunch of methods for creating CommandInfo objects: GetCmdlet(), GetCmdletByTypename() , GetCommand(), etc. and the PowerShell object has an AddCommand() overload that takes CommandInfo. So there's really no need to explicitly create `PSCommand' objects.
construct a PSCommand instance well before actually getting to the internal PowerShell object,
That seems kind of backwards. Why don't you create the PowerShell object first, then pass it around instead of the command objects? A PowerShell API object is really just a future computation that's reified when you call Invoke(). The intent of the PowerShell class was to hold all of the metadata for that computation.
TylerLeonhardtInvocationIntrinsics has a bunch of methods for creating CommandInfo objects: GetCmdlet(), GetCmdletByTypename() , GetCommand(), etc. and the PowerShell object has an AddCommand() overload that takes CommandInfo. So there's really no need to explicitly create `PSCommand' objects.
Can't make a CommandInfo of just a generic script though. Also can't add parameters, multiple statements, or multiple pipeline elements.
construct a PSCommand instance well before actually getting to the internal PowerShell object,
That seems kind of backwards. Why don't you create the PowerShell object first, then pass it around instead of the command objects?
One so that we can cache instances, two so that state details like nested vs remote vs local type state can be determined way later in the code path.
A PowerShell API object is really just a future computation that's reified when you call Invoke().
The intent of the PowerShell class was to hold all of the metadata for that computation.
True but it's got a lot more metadata than just the command that needs to be invoked. It's got all the streams, whether it's nested, what runspace it's going on, current invocation state.
TylerLeonhardt We'd still need to be on the pipeline thread or we'd hit some pretty nasty race conditions. Most of the slowness problems we have are around managing execution on that thread, I don't think skipping the command execution specifically would save us much.
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
TylerLeonhardt commentedon Apr 10, 2020
Yes, we have to use reflection to achieve this in PowerShell Editor Services:
TylerLeonhardt/PowerShellEditorServices@cc24162#diff-fa9220ea78f2263973eaab89e4e26572
There should be better API surface area here for us to take advantage of.
iSazonov commentedon Apr 11, 2020
The new public API should be approved by PowerShell Committee.
/cc Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw)
Also question - should it be in 7.0 Servicing and SDK?
SteveL-MSFT commentedon Apr 15, 2020
@PowerShell/powershell-committee reviewed this, the
PowerShellclass already exposes a methodAddCommand()that takes aCommandInfoso some concerns regarding passing in aCommandInfofrom one runspace into another that may be out of date is already an issue, so from that perspective, it seems there is no concern about making this public since it's already public via thePowerShellclass.bpayette commentedon Apr 16, 2020
TylerLeonhardt
InvocationIntrinsicshas a bunch of methods for creatingCommandInfoobjects:GetCmdlet(),GetCmdletByTypename(),GetCommand(), etc. and thePowerShellobject has anAddCommand()overload that takesCommandInfo. So there's really no need to explicitly create `PSCommand' objects.Patrick Meinecke (@SeeminglyScience)
That seems kind of backwards. Why don't you create the
PowerShellobject first, then pass it around instead of the command objects? APowerShellAPI object is really just a future computation that's reified when you callInvoke(). The intent of thePowerShellclass was to hold all of the metadata for that computation.SeeminglyScience commentedon Apr 16, 2020
Can't make a
CommandInfoof just a generic script though. Also can't add parameters, multiple statements, or multiple pipeline elements.One so that we can cache instances, two so that state details like nested vs remote vs local type state can be determined way later in the code path.
True but it's got a lot more metadata than just the command that needs to be invoked. It's got all the streams, whether it's nested, what runspace it's going on, current invocation state.
TylerLeonhardt commentedon Apr 18, 2020
I don't want to derail this discussion - but for context, in PSES we have this helper method to get
CommandInfo's for use in Intellisense help:https://github.com/PowerShell/PowerShellEditorServices/blob/765c76c930ffcc7f4727a2d1f1dd7ee3ac71e4ee/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs#L64-L105
because it's:
CommandInfo'sI stumbled upon this internal API
CommandDiscovery.LookupCommandInfoand was wondering if this could be leveraged instead since it:however... I have concerns about thread safety with that API...
Bruce Payette (@bpayette) any thoughts?
SeeminglyScience commentedon Apr 18, 2020
TylerLeonhardt We'd still need to be on the pipeline thread or we'd hit some pretty nasty race conditions. Most of the slowness problems we have are around managing execution on that thread, I don't think skipping the command execution specifically would save us much.
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.