Verbose cmdletbinding not passing to module functions

Welcome Forums General PowerShell Q&A Verbose cmdletbinding not passing to module functions

This topic contains 3 replies, has 3 voices, and was last updated by

3 years, 7 months ago.

  • Author
  • #28755

    Points: 0
    Rank: Member

    It appears that when I call the script with -Verbose, that the CmdletBinding typically applies to functions called that have the CmdletBinding attribute as well, but when I use Import-Module with a path to a psm1 file it does not pass the Verbose parameter to the functions exported in that module.


    Import-Module $PSScriptRoot\Module.psm1 -Verbose:$false


    function Test-Verbose
        Write-Verbose "Verbose is enabled"
    Export-ModuleMember -Function *
    .\Script.ps1 -Verbose

    The script will not display verbose output and the $VerbosePreference is reported as SilentlyContinue.

    If I change Script.ps1 to call Test-Verbose -Verbose:$VerbosePreference it works like CmdletBinding is enabled.

    So what is different with a module loaded by path versus loaded by name.


    Name                           Value                                                                                                                                                                                                                             
    ----                           -----                                                                                                                                                                                                                             
    PSVersion                      4.0                                                                                                                                                                                                                               
    WSManStackVersion              3.0                                                                                                                                                                                                                               
    CLRVersion                     4.0.30319.34209                                                                                                                                                                                                                   
    BuildVersion                   6.3.9600.17400                                                                                                                                                                                                                    
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}                                                                                                                                                                                                              
    PSRemotingProtocolVersion      2.2
  • #28756

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    So – maybe this is just your example here? – you've shown a .ps1 file, not a script module. Did you indeed test this with a .psm1? And the only difference was, in one case you loaded it by path, and in another case you had it in PSModulePath?

  • #28757

    Points: 0
    Rank: Member

    That's what led me to write the Get-CallerPreference command. The main problem is that variables in the caller's scope (when the caller is in a different script module / session state, and the caller's scope is not Global) are not inherited by the module. See for more information (and a link to the module on the TechNet Gallery).

    You can also install it with PowerShellGet: Install-Module PreferenceVariables

  • #28758

    Points: 0
    Rank: Member

    Thanks Dave, that's exactly it.

The topic ‘Verbose cmdletbinding not passing to module functions’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort