fix: PowerShell.Create(Runspace) has no such overload on PS 5.1 - #501
Open
HeyItsGilbert wants to merge 1 commit into
Open
HeyItsGilbert wants to merge 1 commit into
HeyItsGilbert wants to merge 1 commit into
Conversation
HeyItsGilbert
requested review from
steviecoaster and
vexx32
as code owners
September 18, 2026 17:36
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved issues were identified, and compatibility was verified across PowerShell 5.1 and 7.
Pull request overview
Fixes PowerShell runspace creation compatibility with Windows PowerShell 5.1.
Changes:
- Replaces unsupported
Create(Runspace)calls withCreate()plus.Runspaceassignment. - Updates the affected test setup.
- Verified on PowerShell 5.1 and 7.
File summaries
| File | Description |
|---|---|
Tests/Functions/Private/New-KoanRunspace.Tests.ps1 |
Updates test setup to use the supported API. |
PSKoans/Private/New-KoanRunspace.ps1 |
Creates and assigns the runspace compatibly. |
PSKoans/Private/Invoke-Koan.ps1 |
Uses the compatible runspace assignment pattern. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
HeyItsGilbert
changed the base branch from
main
to
build/reusable-ci-workflow
September 18, 2026 23:28
[System.Management.Automation.PowerShell]::Create(Runspace) doesn't exist as an overload in Windows PowerShell 5.1's System.Management. Automation (v3.0.0.0, GAC-loaded) -- only Create(), Create(RunspaceMode), and Create(InitialSessionState) are available there. Calling it with a Runspace argument throws: MethodException: Cannot find an overload for "Create" and the argument count: "1". Split into Create() followed by assigning the writable Runspace property instead, which works on both PS 5.1 and 7+. Fixes both call sites (New-KoanRunspace and Invoke-Koan) plus the test file's own use of the same broken pattern. Verified locally: New-KoanRunspace.Tests.ps1 + Invoke-Koan.Tests.ps1 pass under both powershell.exe 5.1 and pwsh 7.
HeyItsGilbert
force-pushed
the
fix/koan-runspace-ps51-create
branch
from
September 18, 2026 23:30
eb21735 to
05ec4f6
Compare
HeyItsGilbert
added this pull request to stack #502
September 18, 2026 23:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
[System.Management.Automation.PowerShell]::Create(Runspace)has no such overload on Windows PowerShell 5.1 — itsSystem.Management.Automationassembly (v3.0.0.0, GAC-loaded) only exposesCreate(),Create(RunspaceMode), andCreate(InitialSessionState). The single-Runspace-argument overload was added later. Calling it with a runspace argument throws:This breaks
New-KoanRunspace, and transitivelyInvoke-Koanand anything that calls it (Get-Karma, etc.) on Windows PowerShell 5.1.Fix
Split the call into
[powershell]::Create()followed by assigning the writable.Runspaceproperty, which works identically on PS 5.1 and 7+. Fixed all three sites using the broken pattern:PSKoans/Private/New-KoanRunspace.ps1PSKoans/Private/Invoke-Koan.ps1Tests/Functions/Private/New-KoanRunspace.Tests.ps1(the test itself used the same broken call)Verification
Built the module and ran the actual affected Pester suites against the built output:
powershell.exe):New-KoanRunspace.Tests.ps1+Invoke-Koan.Tests.ps1— 7/7 passed (previously threw theMethodExceptionabove).Get-Karma.Tests.ps1— 23/23 passed.