Repository navigation
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime
Description
I've been reviewing #4568 and related issues trying to understand the design intent of the differences between $VerbosePreference and -Verbose, but I'm coming up short. Import-Module seems to pass $VerbosePreference to the module scriptblock, but the value of the -Verbose parameter does not pass through. On the other hand, the value of -Verbose passes through to a function defined in the module when it is called.
- Should the value of
-Verbosepassed toImport-Modulebe reflected by$VerbosePreferencewhen the module's scriptblock is executed? - If not, what is the reasoning behind this?
- Is there any way to access the value of
-Verbosefrom within the scriptblock imported byImport-Module?
Steps to reproduce
#m.psm1
$args[0].vp = $VerbosePreference # "ModulePref"
function ModuleFunction {
[CmdletBinding()]
param()
[pscustomobject]@{
vp = $VerbosePreference # "FuncPref","FuncPrefNoArg"
v = $PSCmdlet.
MyInvocation.
BoundParameters['Verbose'] # "FuncArg"
}
}@(
@{ vp='Continue' ; v=$true }
@{ vp='Continue' ; v=$false }
@{ vp='SilentlyContinue' ; v=$true }
@{ vp='SilentlyContinue' ; v=$false }
) |
. {
process {
$h= @{}
$VerbosePreference = $_.vp # "CallerPref"
Import-Module $PSScriptRoot\m.psm1 -Force `
-args $h `
-Verbose:$_.v # "CallerArg"
$mf = ModuleFunction -Verbose:$_.v # "CallerArg"
[pscustomobject]@{
CallerPref = $_.vp
CallerArg = $_.v
ModulePref = $h.vp
FuncPref = $mf.vp
FuncArg = $mf.v
FuncPrefNoArg = ModuleFunction | % vp
}
}} | ftExpected behavior
Note the difference in the "ModulePref" column.
CallerPref CallerArg ModulePref FuncPref FuncArg FuncPrefNoArg
---------- --------- ---------- -------- ------- -------------
Continue True Continue Continue True Continue
Continue False SilentlyContinue SilentlyContinue False Continue
SilentlyContinue True Continue Continue True SilentlyContinue
SilentlyContinue False SilentlyContinue SilentlyContinue False SilentlyContinue
Actual behavior
CallerPref CallerArg ModulePref FuncPref FuncArg FuncPrefNoArg
---------- --------- ---------- -------- ------- -------------
Continue True Continue Continue True Continue
Continue False Continue SilentlyContinue False Continue
SilentlyContinue True SilentlyContinue Continue True SilentlyContinue
SilentlyContinue False SilentlyContinue SilentlyContinue False SilentlyContinue
Environment data
Name Value
---- -----
PSVersion 7.1.0-preview.2
PSEdition Core
GitCommitId 7.1.0-preview.2
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Reacted by boernsen and Artem Pronichkin
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime
Activity
JustinGrote commentedon Apr 8, 2021
It also has different behavior if you use
-Forceor not. If you use-Force, it will ignore-Verbosesetting.microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
boernsen-development commentedon Jul 8, 2025
I find this behavior very confusing. Why is it closed? Are there any practicable workarounds?
Manually passing the "correct" VerbosePreference to every function seems tedious and unnecessarily polutes the code.