VERBOSE suppression for import module

I import Carbon into my PowerShell script; however, when running my script with -Verbose, Carbon also outputs many VERBOSE statements.

Is it possible to use the import module so that I can ignore the detailed instructions in the imported module and leave only my own?

+6
source share
5 answers

Try importing carbon module -Verbose: $ false

+14
source

I could not get the solutions above to work with all modules (I am using Powershell 4.0). This is the solution I used, and so far it has worked with every module I use:

At the top of my script file, I have this to make -Verbose work for the script (the script has no parameters):

[CmdletBinding()] Param() 

Then, when I am ready to import the modules, I do this:

 $SaveVerbosePreference = $global:VerbosePreference; $global:VerbosePreference = 'SilentlyContinue'; Import-module "Whatever"; $global:VerbosePreference = $SaveVerbosePreference; 

Then I just call the script like this:

 PowerShell -file something.ps1 -Verbose 
+2
source

Import module Carbon -Verbose: $ false | Out of null

+1
source

I think a better solution than the one noted here is to redirect verbose output to another thread. This way you can print the output if you need it and it will not be swollen forever:

 Import-Module Carbon 4>&5 

This redirects verbose stream (4) to debug stream (5). When you run your script using Verbose, it will not output verbal lines from the Import-Module, but you can return it by running the script using the -Debug switch.

+1
source

It seems that Carbon is a script module, can you set $script:VerbosePreference (or just $VerbosePreference ) to 'SilentlyContinue' inside the carbon.psm1 module carbon.psm1 . Module volume should do the trick.

0
source

All Articles