Skip to content

Add S.M.A.PowerShell.Create method overload with Runspace argument#8057

Merged
adityapatwardhan merged 12 commits intoPowerShell:masterfrom
KirkMunro:powershell-create-with-runspace-overload
Jan 7, 2019
Merged

Add S.M.A.PowerShell.Create method overload with Runspace argument#8057
adityapatwardhan merged 12 commits intoPowerShell:masterfrom
KirkMunro:powershell-create-with-runspace-overload

Conversation

@KirkMunro
Copy link
Contributor

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.Create inside of a using statement, and then for each command they want to invoke, create a PowerShell instance via PowerShelll.Create from 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.Create method overload that accepts a Runspace object so that it is easier for developers to follow this model in their code.

PR Checklist

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 17, 2018

@KirkMunro It would be great if you would link two gists with samples before and after the change to demo benefits.

@iSazonov iSazonov added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Oct 17, 2018
@KirkMunro
Copy link
Contributor Author

@iSazonov Good idea: https://gist.github.com/KirkMunro/9288214d59a89b965974852eb985eff5.

@adityapatwardhan
Copy link
Member

@KirkMunro I believe this can be done using the overload for IntialSessionState. Which in effect creates a runspace and opens it. Am I missing something?

public static PowerShell Create(InitialSessionState initialSessionState)
{
PowerShell result = Create();
result.Runspace = RunspaceFactory.CreateRunspace(initialSessionState);
result.Runspace.Open();
return result;
}

@KirkMunro
Copy link
Contributor Author

@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.

@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Oct 24, 2018

@PowerShell/powershell-committee is ok with this change to have an overloaded api rather than requiring setting runspace on the property

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Oct 24, 2018
@KirkMunro
Copy link
Contributor Author

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.

Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stale
Copy link

stale bot commented Dec 15, 2018

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.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added Stale and removed Stale labels Dec 15, 2018
@KirkMunro
Copy link
Contributor Author

@SteveL-MSFT What's the hold up on this one? Is it simply outstanding code reviews?

@SteveL-MSFT
Copy link
Member

@KirkMunro Yes, please address the code review feedback. Otherwise, it's good to go.

@KirkMunro
Copy link
Contributor Author

@SteveL-MSFT Unless I'm missing something there are no outstanding code review changes to make. See the discussion between Paul, Ilya and I.

@SteveL-MSFT
Copy link
Member

@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

@adityapatwardhan
Copy link
Member

@daxian-dbw Could you update your review please?

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adityapatwardhan adityapatwardhan merged commit 23f6e8f into PowerShell:master Jan 7, 2019
@adityapatwardhan adityapatwardhan self-assigned this Jan 7, 2019
@adityapatwardhan
Copy link
Member

@daxian-dbw I merged the change. I thought it was assigned to me.

@KirkMunro KirkMunro deleted the powershell-create-with-runspace-overload branch January 7, 2019 21:21
@adityapatwardhan adityapatwardhan added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants