SeeminglyScience / EditorServicesCommandSuite

Collection of editor commands for use in PowerShell Editor Services.
Other
152 stars 13 forks source link

Pwsh 7: Could not resolve `Foreach-Object` 's `-Parallel` argument using ConvertTo-SplatExpression #69

Open SeeminglyScience opened 3 years ago

SeeminglyScience commented 3 years ago

Moved from PowerShell/PowerShellEditorServices#1610 from @ninmonkey (thanks for the report!)


Issue:

Splat is outputting this

$forEachObjectSplat = @{
    Parallel = -Parallel
}
Get-Process | ForEach-Object @forEachObjectSplat {

image

Expected Behaviour

-parallel should splat as a bool

To reproduce

Use ConvertTo-SplatExpression on the For-EachObject

$threadSafeDictionary = [System.Collections.Concurrent.ConcurrentDictionary[string, object]]::new()
Measure-Command -Expression { & {

        Get-Process | ForEach-Object -Parallel -ThrottleLimit 3 -UseNewRunspace {
            $dict = $using:threadSafeDictionary
            $dict.TryAdd($_.ProcessName, $_)
        }
    }
}

$threadSafeDictionary.Values | Format-Table -AutoSize

Behavior

Creating new windows, keeps reproducing the error parallel splat ┐ pwsh 7 1 ┐ part1- 2021-10-01

parallel splat ┐ pwsh 7 1 ┐ part2- 2021-10-01

Environment

test 1

Addon Version
ms-vscode.powershell-preview 2021.10.3
TylerLeonhardt.vscode-inline-values-powershell 0.0.5
TylerLeonhardt.vscode-pester-test-adapter 0.0.23
code --version
code version: 1.59.1, 3866c3553be8b268c8a7f8c0482c0c0177aa8bfa, x64

test 2

Addon Version
justin-grote.powershell-extension-pack 0.0.5
ms-vscode-remote.remote-ssh-edit 0.65.8
ms-vscode.powershell-preview 2021.9.2
nickdemayo.vscode-json-editor 0.3.0
PowerQuery.vscode-powerquery 0.1.23
rust-lang.rust 0.7.8
TylerLeonhardt.vscode-inline-values-powershell 0.0.5
PSVersion GitCommitId OS                           PSEdition
--------- ----------- --                           ---------
7.1.4     7.1.4       Microsoft Windows 10.0.19043 Core

code-insiders --version
1.62.0-insider, 284e0db6c4cac1e557a43cd6691babdaafc2e1a9, x64