GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add S.M.A.PowerShell.Create method overload with Runspace argument by KirkMunro · Pull Request #8057 · PowerShell/PowerShell

Conversation

@KirkMunro

@KirkMunro Kirk Munro (KirkMunro) commented Oct 17, 2018

Copy link
Copy Markdown
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

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
  • User-facing changes
    • Not Applicable
    • OR
    • User-facing Documentation needed
      • Issue filed - Issue link: Update PowerShell.Create docs to include the new overload that has a Runspace argument MicrosoftDocs/PowerShell-Docs#3131
  • Testing - New and feature
    • Not Applicable or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
      • Add [feature] if the change is significant or affects feature tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jazzdelightsme reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@KirkMunro
add Create overload with Runspace argument
20058cb
@KirkMunro
Kirk Munro (KirkMunro) requested review from Bruce Payette (BrucePay) and Dongbo Wang (daxian-dbw) as code owners October 17, 2018 02:36
@KirkMunro
CodeFactor changes
034dda7
@iSazonov

Ilya (iSazonov) commented Oct 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov Ilya (iSazonov) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Oct 17, 2018
@KirkMunro

Kirk Munro (KirkMunro) commented Oct 17, 2018

Copy link
Copy Markdown
Contributor Author

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

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Oct 18, 2018

Copy link
Copy Markdown
Member

Kirk Munro (@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?

PowerShell/src/System.Management.Automation/engine/hostifaces/PowerShell.cs

Lines 853 to 861 in 4e5e390

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Oct 18, 2018

Copy link
Copy Markdown
Contributor Author

Aditya Patwardhan (@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.

adityapatwardhan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adityapatwardhan
Aditya Patwardhan (adityapatwardhan) requested changes Oct 18, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

PaulHigin
Paul Higinbotham (PaulHigin) suggested changes Oct 23, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Oct 24, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (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

Kirk Munro (KirkMunro) commented Oct 27, 2018

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kirk Munro (KirkMunro) added 4 commits November 4, 2018 15:33
@KirkMunro
Merge branch 'master' into powershell-create-with-runspace-overload
089662b
@KirkMunro
added null check and Pester test
51b124b
@KirkMunro
codefactor changes
15f5d16
@KirkMunro
codefactor changes
8a84e36
PaulHigin
Paul Higinbotham (PaulHigin) approved these changes Nov 5, 2018
View reviewed changes

@PaulHigin Paul Higinbotham (PaulHigin) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
adityapatwardhan
Aditya Patwardhan (adityapatwardhan) reviewed Nov 12, 2018
View reviewed changes
Comment thread test/powershell/engine/Api/BasicEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Aditya Patwardhan (adityapatwardhan) and others added 4 commits November 12, 2018 15:52
@adityapatwardhan @KirkMunro
Code review change
2c176bb
Co-Authored-By: KirkMunro <[email protected]>
@KirkMunro
Merge branch 'master' into powershell-create-with-runspace-overload
f02b4c7
@KirkMunro
Merge branch 'powershell-create-with-runspace-overload' of https://gi…
ae8f903
…thub.com/KirkMunro/PowerShell into powershell-create-with-runspace-overload
@KirkMunro
fixed pester test
10c0404
@stale

stale Bot commented Dec 15, 2018

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot added Stale and removed Stale labels Dec 15, 2018
@KirkMunro

Kirk Munro (KirkMunro) commented Dec 17, 2018

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Dec 20, 2018

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Dec 20, 2018

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov Ilya (iSazonov) assigned Dongbo Wang (daxian-dbw) Dec 20, 2018
@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Dec 20, 2018

Copy link
Copy Markdown
Member

Kirk Munro (@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.

Aditya Patwardhan (@adityapatwardhan) should review your changes and approve

KirkMunro reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) requested changes Dec 20, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Kirk Munro (KirkMunro) added 2 commits December 21, 2018 10:29
@KirkMunro
Merge branch 'master' into powershell-create-with-runspace-overload
432733a
@KirkMunro
added comments per code review
e350008
adityapatwardhan
Aditya Patwardhan (adityapatwardhan) approved these changes Jan 7, 2019
View reviewed changes
@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Jan 7, 2019

Copy link
Copy Markdown
Member

Dongbo Wang (@daxian-dbw) Could you update your review please?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) approved these changes Jan 7, 2019
View reviewed changes

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 23f6e8f into PowerShell:master Jan 7, 2019
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) self-assigned this Jan 7, 2019
@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Jan 7, 2019

Copy link
Copy Markdown
Member

Dongbo Wang (@daxian-dbw) I merged the change. I thought it was assigned to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
Kirk Munro (KirkMunro) deleted the powershell-create-with-runspace-overload branch January 7, 2019 21:21
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Jan 7, 2019
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@KirkMunro @adityapatwardhan
Add S.M.A.PowerShell.Create method overload with Runspace argument (P…
c0b8c18
…owerShell#8057)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw approved these changes
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) adityapatwardhan approved these changes
@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
+1 more reviewer
@PaulHigin Paul Higinbotham (PaulHigin) PaulHigin approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

@adityapatwardhan Aditya Patwardhan (adityapatwardhan)

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@KirkMunro @iSazonov @adityapatwardhan @SteveL-MSFT @daxian-dbw @PaulHigin
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.