-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate execution preferences beyond script module scope #221
base: master
Are you sure you want to change the base?
Propagate execution preferences beyond script module scope #221
Conversation
I am surprised that this has been broken for as long as hit has. I find that this issue makes The real danger is most people don't realize it works this way. |
Agreed. This issue renders every common parameter effectively unusable for script module authors whenever they call commands external to their modules because most authors will not understand why some commands work without issue and others completely ignore the requested preference. I can only hope we can get it approved for a fix as soon as possible. |
Stumbled across this today as well when I refactored code into a common script module where as a result of that the |
@joeyaiello @SteveL-MSFT is this one one your guys' radar at all? 💖 |
I am following the rabbit trail from Powershell\Powershell#4568, and am trying to solve this as well. I see DWyatt's "Get-CallerPreference" script, and am thinking of using something similar for now. There is an edge case to this proposal that may need considering. I have a module with a cmdlet(Adv. Function), that contains verbose messages to call out information, and is called by other higher-level cmdlets a lot of times (possibly hundreds of times). When I do IMO, I think opting-out of passing these preferences would be useful. But by default, I would like to see "Calling cmdlets" pass their preferences onto the "Called cmdlets". Mostly, because there isn't a preferred/documented/best-practice way to make this work currently. |
@bwright86 I can see that potentially being useful, but I think at least as an initial implementation it would be preferable that it affect everything; as you note, those authors can selectively pick and choose which cmdlets' preference variables are passed along by simply manually overriding the -Verbose (etc) params when their function calls other functions. I'm not sure a completely separate preference is necessary, but if it does end up being desirable I could see potentially something like an additional property in |
I agree with you, and I think what is being pointed out by this RFC and many SO questions, is that there isn't a good way to code the preferred way. So if this RFC goes forward, it would be nice to document the "opt-out" way for the use case i mentioned. So I wasn't looking for anything to be implemented from my edge case, but maybe something to keep in mind, or integrate into the RFC language. I think manually overriding the preference like you mentioned may be a good way around it, and calling it out in the As a side note, the issue I was facing today that caused me to go down this rabbit hole, was the |
I am surprised that such an old issue is not yet fixed. I have lost many hours to find why execution preferences do not propagate between modules. It's absolutely unacceptable that this thing happens. |
Just came across this while checking to ensure that my WhatIf preference would transfer to functions in a helper script. It seems that due to this issue they will not without extra code to explicitly transfer the preference. The fact that the behavior is different between binary modules and script modules if very confusing and not what users will expect. It's been over 4 years. This should be fixed. |
I finally went a slightly different and somewhat hacky route, using $PSDefaultParameterValues = @{
"*-MJL*:Verbose" = { $PSBoundParameters['Verbose'] -or $VerbosePreference -eq 'Continue' }
"*-MJL*:WhatIf" = { $PSBoundParameters['WhatIf'] -or $WhatIfPreference }
} The only down side is that you have to specify |
This RFC was originally proposed as part of a collection of RFCs in PR #187. I am separating those RFCs into separate PRs to better adhere to the RFC process.