My verbose logging does not output for a script that gets called when my module gets imported. The module manifest contains a script to process for when the module is imported. Now when I run the cmdlet to import the module with the verbose parameter set, no verbose logging outputs from the script.
# within Module Manifest # Script files (.ps1) that are run in the caller's environment prior to importing this module. ScriptsToProcess = '.\ScriptToProces.ps1'
# run the following in PowerShell Import-Module MyModule -Verbose
I expect the verbose logging I set up in my ".\ScriptToProcess.ps1" script to output, but it doesn't. I am sure this has something do with scope, but I have tried a few things and have been unsuccessful.
I thought as a solution to be able to verify if the -Verbose parameter was used with Import-Module, then I can set my $VerboseParameter from within my script. I have not figured it out.
I'm fairly sure that's by design. However, it'd make sense to log it as an Issue on the PowerShell GitHub repo if you think the behavior should be different.
I found a (call it if you'd like) "work-around" for this scenario.
I added a parameter to my 'ScriptToProcess.ps1' called [bool] $Verbosity and add an argument to the import module like such: "Import-Module MyModule -ArgumentList $true". That arg is accepted by 'ScriptsToProcess' and I have additional logic to set the $VerbosePreference to "Continue" if the $true arg is passed.
Ill definitely add it to the PowerShell Github to see what the PowerShell team says.
You must be logged in to reply to this topic.