Hey everyone! I've been using verbose output quite a bit while designing my modules, and I typically keep verbose enabled during testing. It really helps me catch those situations that aren't errors but still aren't quite right. However, I've been frustrated with certain modules that tend to flood me with verbose messages. A prime example is the NetTCPIP module that activates when I run Test-NetConnection. Are there any ways to specifically exclude certain cmdlets, like Import-Module, from following the VerbosePreference setting?
4 Answers
Another way to deal with this is by directly passing `-Verbose:$false` to any command you want to stop from displaying verbose output. Just keep in mind that Import-Module in PowerShell 5.1 may not respect this. I've found that using `Import-Module -Name MyModule 4>$null` is the only way to suppress its verbose output effectively.
I've come across a personal fix where I just use Write-Information instead of Write-Verbose. It seems to work well for most scenarios for me and doesn't produce those annoying verbose messages.
If you have a specific cmdlet or function that you want to avoid verbose output for entirely, consider creating an alias for it in your PowerShell profile with `-Verbose:$false` included.
You can leverage the `$PSDefaultParameterValues` automatic variable to handle this. For example, to turn off verbose output specifically for Import-Module, you could set it up like this:
`$PSDefaultParameterValues = @{'Import-Module:Verbose' = $false}`
That's a solid workaround! I'll definitely give that a try.