Invoke-Command: improve handling of variables with $using: expression#16113
Conversation
I wonder why we need the workaround if we can prepare full fix. If I understand correctly, with ComputerName we create new runspace but do not open it in |
Implementing proper version detection for the |
|
Can I get some guidance on the two tests that have failed? It looks like I'd also appreciate any suggestions on writing a Pester test for this issue. I don't think any of the current remoting tests target a remote computer, so they don't offer much guidance. So far I've been testing against computers available to me, but obviously that's too context-dependent to be of use to anyone else. Are there any designated endpoints for this sort of testing? |
|
I restarted CI-static. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
| if (varAst != null) | ||
| { | ||
| string varName = varAst.VariablePath.UserPath; | ||
| var varPath = varAst.VariablePath; |
There was a problem hiding this comment.
Please use the type name instead of var here
| if (astStartOffset >= endOffset) { break; } | ||
|
|
||
| string varName = varAst.VariablePath.UserPath; | ||
| var varPath = varAst.VariablePath; |
| foreach (var varAst in usingVariables) | ||
| { | ||
| string varName = varAst.VariablePath.UserPath; | ||
| var varPath = varAst.VariablePath; |
|
Not sure what the state of testing is for |
|
Tagging @PaulHigin for review as well |
|
Git/GitHub novice question: when updating from the master branch, I should have used a fast-forward merge to avoid creating a separate merge commit, right? How much of a problem is it that I, uh, didn't do that? |
|
@dwtaber Never mind - we use "squash and merge" to get one commit in main branch. |
PaulHigin
left a comment
There was a problem hiding this comment.
Changes look good to me.
|
@rjmholt, judging by its file history, it looks like |
|
@dwtaber Changes from this PR exists in the master branch. The PR will not be included in 7.2.0-rc.1 though. It will be included in 7.3.0-preview.1. |
Ah, okay. Thanks for clarifying! |
|
🎉 Handy links: |
|
I really wish this had made it into the stable release of 7.2, I try to avoid using preview-exclusive stuff in my code, so having to wait for 7.3's stable release really sucks. Is there any chance this could be slipped into a 7.2 build, i.e. 7.2.2? |
|
@PowerShell/powershell-maintainers |
PR Summary
This PR improves
Invoke-Command's handling of cases that combine$using:expressions with variable namespace notation when the-ComputerNameparameter is used.Fixes #9204
Fixes #16019
PR Context
When the
-ComputerNameparameter is used,Invoke-Commandis unable to check which version of PowerShell is available on the remote computer and assumes v2.0. Because PowerShell 2.0 can't parse$using:expressions, theScriptBlockis modified before sending, with$using:variables renamed to replace the$using:expression with$__using_. Currently, the code that renames these variables doesn't check whether the variable path is qualified. In cases where variable namespace notation is used, this code produces variable names like$__using_env:foo, preventing the remote computer from parsing the variables correctly. The changes in this PR add handling for qualified variable paths, producing variable names like$__using_env_fooThis PR does not fix all issues with the handling of
$using:expressions. Variable names that include special characters still aren't parsed correctly, for instance. Since a user technically could name a variable$__using_env_foo, this might be considered an "unlikely grey area" breaking change. Long-term, it might be worth reconsidering howInvoke-Commandhandles the-ComputerNameparameter; always falling back to v2.0 seems unnecessarily restrictive.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).