Skip to content

-Verbose not passed to other module's functions (as opposed to $VerbosePreference) #25739

Closed as duplicate

Description

Prerequisites

Steps to reproduce

# Two modules:
# - one with functions Foo and Bar
# - one with function Another
# Foo call's Bar from the same module and Another from a different module
$null = New-Module {
  function Foo {
    [CmdletBinding()] param()
    # own output
    Write-Verbose "Foo's verbose output."
    # call Bar from same module
    Bar
    # call Another from other module
    Another
  }
  function Bar {
    [CmdletBinding()] param()
    Write-Verbose "Bar's verbose output."
  }
}

$null = New-Module {
  function Another {
    [CmdletBinding()] param()
    Write-Verbose "Another's verbose output."
  }
}

# -Verbose doesn't seem to be passed through to secondary modules
Write-Host "1st attempt (-Verbose):"
Foo -Verbose

# VerbosePreference on the other hand does seem to be passed through to secondary modules
Write-Host "2nd attempt (VerbosePreference):"
$VerbosePreferenceOriginal = $VerbosePreference
$VerbosePreference = 'Continue'
Foo
$VerbosePreference = $VerbosePreferenceOriginal

Expected behavior

1st attempt (-Verbose):
VERBOSE: Foo's verbose output.
VERBOSE: Bar's verbose output.
VERBOSE: Another's verbose output.
2nd attempt (VerbosePreference):
VERBOSE: Foo's verbose output.
VERBOSE: Bar's verbose output.
VERBOSE: Another's verbose output.

Actual behavior

Another's output is missing in the 1st attempt.

1st attempt (-Verbose):
VERBOSE: Foo's verbose output.
VERBOSE: Bar's verbose output.
2nd attempt (VerbosePreference):
VERBOSE: Foo's verbose output.
VERBOSE: Bar's verbose output.
VERBOSE: Another's verbose output.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Jul 8, 2025
  2. similar-issues-ai commented on Jul 8, 2025

    @similar-issues-ai

    We've found some similar issues:

    If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

    Note: You can give me feedback by 👍 or 👎 this comment.

  3. boernsen-development commented on Jul 8, 2025

    @boernsen-development
    Author

    #12516 is indeed similar, but it was not resolved, there were no answers and it is closed, so I opened this one. Feel free to close one or the other as long as one stays open or is resolved or documented or whatever.

  4. mklement0 commented on Jul 8, 2025

    @mklement0
    Contributor

    The real duplicate (also linked to from #12516) is:

    In short:

    • The common -Verbose (switch) parameter is by - problematic - design translated into a function-local $VerbosePreference variable with value 'Continue'.

    • Such a preference variable is not honored across module boundaries : functions in a given module do not see an outside caller's preference variables (though it's possibly to go out of one's way to access them).

  5. microsoft-github-policy-service commented on Jul 9, 2025

    @microsoft-github-policy-service
    Contributor

    📣 Hey @boernsen (@boernsen-development), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

  6. removed
    Needs-Triage
    on Jul 9, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions