Home Dashboard Directory Help
Search

Functions in Script Modules do not inherit variables from the scope of their caller by David Wyatt


Status: 

Active


7
1
Sign in
to vote
Type: Bug
ID: 828782
Opened: 3/5/2014 10:57:09 AM
Access Restriction: Public
0
Workaround(s)
view
3
User(s) can reproduce this bug

Description

When you call a function that's been imported from a psm1 Script Module, variables such as $ErrorActionPreference that have been set in the caller's local scope are not seen by the module's function, unless the calling code sets its variables in the Global scope.
Details
Sign in to post a comment.
Posted by aljodAv on 8/1/2014 at 10:15 AM
It has to be you to ask something so simple. Read this odl report: https://connect.microsoft.com/PowerShell/feedback/details/817140/import-module-cmdlet-fails-to-import-a-module-in-dot-sourcing-mode-in-2-thus-different-child-contexts
Posted by David Wyatt on 7/31/2014 at 11:17 AM
Ah, you again. By all means, demonstrate how to "import a module using DOT SOURCING MODE." Or point to any documentation which states that this is even possible.
Posted by aljodAv on 7/31/2014 at 11:12 AM
You can achieve what you want if you import the module using DOT SOURCING MODE.. The current behavior is correct and it's the same in older versions. Some cmdlets would even work correctly when initializing scripts, if this behavior were different.
Sign in to post a workaround.