-
Couldn't load subscription status.
- Fork 8k
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
It is currently not possible to implement a cmdlet like ForEach-Object or Measure-Command outside of PowerShell because there is no api support for invoking a script block instance in the callers scope - or dot sourcing.
The workaround is quite expensive - it looks something like:
void InvokeInCurrentScope(ScriptBlock sb)
{
var ps = PowerShell.Create(RunspaceMode.CurrentRunspace);
ps.AddScript(sb.ToString());
ps.Invoke();
}This is expensive we must reparse the script block.
There are a couple possible fixes, maybe we do both:
ScriptBlock.Invoke(and family) should expose this parameter in a public api- Add a new api or overload to the
PowerShell.Add*family of commands, something likeAddScriptBlock, or maybe just a new overload onAddCommand.
mklement0 and vexx32
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime