Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters don't work with PowerShell v2 #66

Closed
ALuckyGuy opened this issue Apr 6, 2016 · 6 comments
Closed

Parameters don't work with PowerShell v2 #66

ALuckyGuy opened this issue Apr 6, 2016 · 6 comments

Comments

@ALuckyGuy
Copy link

Try the following script:

1..2|start-rsjob -Name {$_} -ScriptBlock {
param($parm)
        new-object psobject -Property @{
            Result=($parm)
        }
}            
Get-RSjob | Receive-RSJob

With v3 & later, produces the following:

 Result
 ------
      1
      2

With v2 (run with PowerShell -version 2), the output is blank.

 Result
 ------
@proxb proxb self-assigned this Apr 7, 2016
@ALuckyGuy
Copy link
Author

This problem seems to be with Start-RSJob and how PowerShell v2 deals with references to the count property on $null parameters: $null.count returns 0 in v3 and later but in v2 it returns nothing.

So, in Start-RSJob.ps1 if you change the two references to $ArgumentList.count to ($ArgumentList) -and $ArgumentList.count, the example I gave in the OP works in v2 and later:

    $SBParamCount = @(GetParamVariable -ScriptBlock $ScriptBlock).Count
    If ($PSBoundParameters.ContainsKey('InputObject')) {
        If ($ArgumentList.Count -gt 0) {
            $SBParamCount++
        } Else {
            $SBParamCount--
        }
    }
    If ($ArgumentList.Count -ne $SBParamCount -AND $IsPipeline) {
        Write-Verbose 'Will use $_ in Param() Block'
        $Script:Add_ = $True
    } Else {
        $Script:Add_ = $False
    }

to:

    $SBParamCount = @(GetParamVariable -ScriptBlock $ScriptBlock).Count
    If ($PSBoundParameters.ContainsKey('InputObject')) {
        If ( ($ArgumentList) -and $ArgumentList.count -gt 0) {
            $SBParamCount++
        } Else {
            $SBParamCount--
        }
    }
    If ( ($ArgumentList) -and $ArgumentList.count -ne $SBParamCount -AND $IsPipeline) {
        Write-Verbose 'Will use $_ in Param() Block'
        $Script:Add_ = $True
    } Else {
        $Script:Add_ = $False
    }

@proxb
Copy link
Owner

proxb commented Apr 7, 2016

Great! I appreciate the reports that you have been providing. It definitely helps to make this module better for everyone!

@proxb proxb added the Ready label Apr 8, 2016
proxb added a commit that referenced this issue Apr 8, 2016
@proxb
Copy link
Owner

proxb commented Apr 8, 2016

This one appears to break the following attempt with a single item:

1|Start-RSJob -ScriptBlock {$_}

In which there appears to be no data being received.

@proxb proxb removed the Ready label Apr 8, 2016
proxb added a commit that referenced this issue Apr 8, 2016
rollback #66
@proxb proxb added this to the 1.5.6.2 milestone Apr 8, 2016
@proxb
Copy link
Owner

proxb commented Apr 8, 2016

Made some adjustments and it appears to be working now with the new version that I am working on.

@proxb proxb added the Ready label Apr 8, 2016
@proxb proxb modified the milestones: 1.5.6.3, 1.5.6.2 Apr 8, 2016
@proxb
Copy link
Owner

proxb commented Apr 9, 2016

This one should be fixed in the latest release

@ALuckyGuy
Copy link
Author

This looks good for my tests as well. Closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants