Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Dot sourcing a function does not allow $MyInvocation to be used as a default parameter #4840

Copy link
Copy link
@RamblingCookieMonster

Description

@RamblingCookieMonster
Issue body actions

It can be useful to run functions (vs. scripts) in the current scope. @Jaykul's Get-ParameterValues is an example

At the moment, it appears that a dot sourced function does not actually run in the current scope. Apologies if I'm using the wrong phrasing, the example should clarify things:

Steps to reproduce

function Test-MyInvocationParam {
    [cmdletbinding()]
    param($Invocation = $MyInvocation)
    $Invocation
}

function Test-Bug {
    [cmdletbinding()]
    param($a=1)
    . Test-MyInvocationParam
}

(Test-Bug).MyCommand.Name

Expected behavior

Test-Bug

Actual behavior

Test-MyInvocationParam

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.7
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: Th...
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By DesignThe reported behavior is by design.The reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.