Add S.M.A.PowerShell.Create method overload with Runspace argument#8057
Conversation
|
@KirkMunro It would be great if you would link two gists with samples before and after the change to demo benefits. |
|
@KirkMunro I believe this can be done using the overload for PowerShell/src/System.Management.Automation/engine/hostifaces/PowerShell.cs Lines 853 to 861 in 4e5e390 |
|
@adityapatwardhan That only works for one invocation. A single PowerShell instance. The PR allows you to create your runspace and initialize it with the initialSessionState, and then easily use it over, and over, for as many PowerShell instances as you need, keeping each instance in the same runspace that is initialized only once. |
|
@PowerShell/powershell-committee is ok with this change to have an overloaded api rather than requiring setting runspace on the property |
|
FYI, I'm on vacation this week and through the weekend, so I'll catch up on all of this when I am back at home. |
Co-Authored-By: KirkMunro <KirkMunro@users.noreply.github.com>
…thub.com/KirkMunro/PowerShell into powershell-create-with-runspace-overload
|
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
|
@SteveL-MSFT What's the hold up on this one? Is it simply outstanding code reviews? |
|
@KirkMunro Yes, please address the code review feedback. Otherwise, it's good to go. |
|
@SteveL-MSFT Unless I'm missing something there are no outstanding code review changes to make. See the discussion between Paul, Ilya and I. |
|
@KirkMunro you are correct. Unfortunately we're a bit understaffed right now due to the holidays. I expect this to be merged after the new year. @adityapatwardhan should review your changes and approve |
src/System.Management.Automation/engine/hostifaces/PowerShell.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/PowerShell.cs
Outdated
Show resolved
Hide resolved
|
@daxian-dbw Could you update your review please? |
|
@daxian-dbw I merged the change. I thought it was assigned to me. |
PR Summary
When invoking multiple PowerShell commands one at a time from an assembly that does not have PowerShell loaded by default, developers should create a runspace first via
RunspaceFactory.Createinside of a using statement, and then for each command they want to invoke, create a PowerShell instance viaPowerShelll.Createfrom within another using statement, and then after that set the runspace for the PowerShell instance to the runspace they created from the RunspaceFactory. This is cumbersome and unintuitive, and really should be simplified to make it easier to use and understand.This PR adds a new
PowerShell.Createmethod overload that accepts a Runspace object so that it is easier for developers to follow this model in their code.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests