Skip to content

Commit eb21735

Browse files
committed
fix: PowerShell.Create(Runspace) has no such overload on PS 5.1
[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.
1 parent 25c9faf commit eb21735

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

PSKoans/Private/Invoke-Koan.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
}
6262
}
6363

64-
$ps = [powershell]::Create($script:KoanRunspace)
64+
$ps = [powershell]::Create()
65+
$ps.Runspace = $script:KoanRunspace
6566
$ps.AddScript($Script, <# useLocalScope: #> $true) > $null
6667

6768
$ps.AddParameter('Params', $ParameterSplat) > $null

PSKoans/Private/New-KoanRunspace.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function New-KoanRunspace {
2222
$runspace = [runspacefactory]::CreateRunspace()
2323
$runspace.Open()
2424
$runspace.Name = 'PSKoans.KoanRunspace'
25-
$ps = [powershell]::Create($runspace)
25+
$ps = [powershell]::Create()
26+
$ps.Runspace = $runspace
2627

2728
try {
2829
$script = {

Tests/Functions/Private/New-KoanRunspace.Tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Describe 'New-KoanRunspace' {
4444

4545
It 'preloads the runspace with PSKoans' {
4646
$runspace = InModuleScope 'PSKoans' { New-KoanRunspace }
47-
$ps = [powershell]::Create($runspace)
47+
$ps = [powershell]::Create()
48+
$ps.Runspace = $runspace
4849

4950
try {
5051
$ps.AddCommand('Get-Module').AddParameter('Name', 'PSKoans') > $null

0 commit comments

Comments
 (0)