How can I ignore VerbosePreference for specific cmdlets?

0
9
Asked By TechWhiz42 On

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

Answered By ScriptSavant7 On

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.

CodeHero22 -

That's a solid workaround! I'll definitely give that a try.

Answered By VerboseViking On

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.

Answered By PowerPal12 On

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.

Answered By CodeCrafter99 On

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}`

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.