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.
[Script.ps1]
[CmdletBinding()] param() Import-Module $PSScriptRoot\Module.psm1 -Verbose:$false Test-Verbose
[Module.psm1]
function Test-Verbose
{
[CmdletBinding()]
param()
$VerbosePreference
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.
$PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34209
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2