Skip to content

The $using: scope for remoting quietly accepts scope modifiers, but resolves to $null #9204

Closed

Description

Affects both:

  • true scope modifiers such as $global:
  • namespace variable notation such as $function:

Steps to reproduce

Prerequisites:

  • enable remoting on the calling machine
  • run as admin.
# Define a variable and function, both named 'foo'.
function foo { 'func' }; $global:foo = 'var'
# Try to access these definitions remotely via $using
Invoke-Command -ComputerName . { $using:foo; $using:global:foo; $using:function:foo }

Expected behavior

var
var
 'func' 

Actual behavior

var

That is, $using:global:foo and $using:function:foo quietly evaluated to $null.

Environment data

PowerShell Core 6.2.0-rc.1
Windows PowerShell v5.1 

Activity

  1. added
    Issue-Question
    on Mar 22, 2019
  2. added
    WG-Remoting
    on Mar 23, 2019
  3. msftrncs commented on Apr 17, 2019

    @msftrncs
    Contributor

    In the example:

    Invoke-Command -ComputerName . { $using:foo; $using:global:foo; $using:function:foo }

    appears like this via PR # 156 in PowerShell/EditorSyntax:
    image

    The scope can only be the first thing before the :, and after that, : is a valid variable character. In this case, using is the scope.

  4. mklement0 commented on Apr 17, 2019

    @mklement0
    ContributorAuthor

    Thanks, Carl Morris (@msftrncs), but : chars. aren't directly usable in variable names proper:

    PS> ${foo:bar} = 'hi'
    Cannot find drive. A drive with the name 'foo' does not exist.

    While you can use them if you always use namespace variable notation, that is obviously impractical:

    PS> ${variable:foo:bar} = 'hi'; ${variable:foo:bar}
    hi  # OK, but only via reference to drive variable:

    A much more sensible behavior would therefore be to support scope modifiers / drive references even after $using:, as attempted in the OP.

    While technically a breaking change, it strikes me as a clear-cut case of a bucket 3 change.

  5. vexx32 commented on Apr 17, 2019

    @vexx32
    Collaborator

    Mmm. : isn't usually a valid variable character. Actually setting that variable in any reasonable way would be literally impossible, as it'd resolve to the proper expected item instead of the variable name containing the bunk character..

    Still a bug, in my opinion.

  6. msftrncs commented on Apr 18, 2019

    @msftrncs
    Contributor

    See PowerShell/EditorSyntax#49 (comment), while the first : separates the drive or scope from the variable name, all other : are accepted as variable name (as long as they are not doubled, because then that's a static accessor).

  7. added a commit that references this issue on Sep 16, 2021
    c5c6882
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-FixedWG-Remoting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions