When specifying verbose preference this will only be inherited by the scripts module functions, if specified in the global scope.
However, it is possible to use an advanced function to access the variable preference using the ‘$PSCmdlet.GetVariableValue()’ method to access the SessionState object and inherit the preference value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param ( | |
$VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference') | |
) |
The important part of the above is that the parameter block contains [CmdletBinding()] attributes, without this the $PSCmdlet value will be null.