You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Named parameters passed to imported functions don't work within the PowerShell ISE or VSCode's Powershell plugin's Integrated Console. Works fine otherwise, including within VSCode's PS console (unrelated to the plugin). Not sure if this is a PoshRSJob bug or not, but if not there ought to at least be some kind of warning or error if running within these well-known consoles.
I'm running Windows 10, PS version 5.1.14393.2430, VSCode v1.27.2, Powershell plugin v 1.9.0
Below is an example that shows the problem. Notice that if a parameter has the same name as a local variable of a caller, things appear to be fine because the references take on the value from the caller's local scope. That made figuring this out really confusing.
Also, notice calling a function declared within the scriptblock with named parameters works fine. Outputing the $args value within the called function shows the difference in how the function gets called
functionshow-parm( $s,$sameName ) {
# because this function has a parameter with the same name as a local variable for the caller,# that parameter seems to be set correctly. It's not though.
[pscustomobject]@{ str1=$sstr2=$sameNameargCount=$args.countargs=$args }
}
# the imported show-parm function won't get parameter values passed in the VSCode integrated console
[pscustomobject]@{ str='a string'sameName='misleading' } |Start-RSJob`-FunctionsToImport 'show-parm'-script {
$str=$_.str$sameName=$_.sameName"Before call: [$str] [$sameName]"show-parm-s $str-sameName $sameName
} |wait-rsjob|receive-rsjob# the locally declared show-parm function receives parameters corrected
[pscustomobject]@{ str='a string'sameName='misleading' } |Start-RSJob-script {
functionshow-parm( $s,$sameName ) {
[pscustomobject]@{ str1=$sstr2=$sameNameargCount=$args.countargs=$args }
}
$str=$_.str$sameName=$_.sameName"Before call: [$str] [$sameName]"show-parm-s $str-sameName $sameName
} |wait-rsjob|receive-rsjobget-rsjob|remove-rsjob
The text was updated successfully, but these errors were encountered:
As far as I see there is some error in function definition under ISE
Place $DebugPreference = 'Continue' before you script and you see:
clean PS
ОТЛАДКА: [BEGIN]
ОТЛАДКА: Definition: param($s,$sameName)
# because this function has a parameter with the same name as a local variable for the caller,# that parameter seems to be set correctly. It's not though.
[pscustomobject]@{ str1=$sstr2=$sameNameargCount=$args.countargs=$args }
ОТЛАДКА: ListCount: 0
ISE
ОТЛАДКА: [BEGIN]
ОТЛАДКА: Definition:
# because this function has a parameter with the same name as a local variable for the caller,# that parameter seems to be set correctly. It's not though.
[pscustomobject]@{ str1=$sstr2=$sameNameargCount=$args.countargs=$args }
ОТЛАДКА: ListCount: 0
take a note that under ISE there is no param() block !
But I Can't reproduce it with plain test like
Named parameters passed to imported functions don't work within the PowerShell ISE or VSCode's Powershell plugin's Integrated Console. Works fine otherwise, including within VSCode's PS console (unrelated to the plugin). Not sure if this is a PoshRSJob bug or not, but if not there ought to at least be some kind of warning or error if running within these well-known consoles.
I'm running Windows 10, PS version 5.1.14393.2430, VSCode v1.27.2, Powershell plugin v 1.9.0
Below is an example that shows the problem. Notice that if a parameter has the same name as a local variable of a caller, things appear to be fine because the references take on the value from the caller's local scope. That made figuring this out really confusing.
Also, notice calling a function declared within the scriptblock with named parameters works fine. Outputing the $args value within the called function shows the difference in how the function gets called
The text was updated successfully, but these errors were encountered: