Import-Module cmdlet doesn't respect -Verbose:$false switch
See original GitHub issueYou can’t turn off verbose output when importing modules by setting the -Verbose switch’s value to $false.
Steps to reproduce
$VerbosePreference = 'Continue'
Import-Module -Name 'PSDesiredStateConfiguration' -Verbose:$false -Force
Expected behavior
I would expect there to be no verbose output when importing the module.
Actual behavior
I see verbose output:
VERBOSE: Exporting function 'Configuration'.
VERBOSE: Exporting function 'New-DSCCheckSum'.
VERBOSE: Exporting function 'Get-DscResource'.
VERBOSE: Exporting function 'ConvertTo-MOFInstance'.
VERBOSE: Exporting function 'Get-MofInstanceText'.
VERBOSE: Exporting function 'Get-PositionInfo'.
VERBOSE: Exporting function 'Node'.
VERBOSE: Exporting function 'Update-ConfigurationErrorCount'.
VERBOSE: Exporting function 'Get-ConfigurationErrorCount'.
VERBOSE: Exporting function 'Set-PSDefaultConfigurationDocument'.
VERBOSE: Exporting function 'Get-PSDefaultConfigurationDocument'.
VERBOSE: Exporting function 'Get-PSCurrentConfigurationNode'.
VERBOSE: Exporting function 'Set-PSCurrentConfigurationNode'.
VERBOSE: Exporting function 'Set-NodeResources'.
VERBOSE: Exporting function 'Test-NodeResources'.
VERBOSE: Exporting function 'Add-NodeKeys'.
VERBOSE: Exporting function 'Get-InnerMostErrorRecord'.
VERBOSE: Exporting function 'Initialize-ConfigurationRuntimeState'.
VERBOSE: Exporting function 'ValidateUpdate-ConfigurationData'.
VERBOSE: Exporting function 'Test-ModuleReloadRequired'.
VERBOSE: Exporting function 'Configuration'.
VERBOSE: Exporting function 'ImportCimAndScriptKeywordsFromModule'.
VERBOSE: Exporting function 'Write-NodeMOFFile'.
VERBOSE: Exporting function 'ValidateNodeResources'.
VERBOSE: Exporting function 'ValidateNoCircleInNodeResources'.
VERBOSE: Exporting function 'StrongConnect'.
VERBOSE: Exporting function 'Test-MofInstanceText'.
VERBOSE: Exporting function 'Get-EncryptedPassword'.
VERBOSE: Exporting function 'Get-PublicKeyFromStore'.
VERBOSE: Exporting function 'Get-PublicKeyFromFile'.
VERBOSE: Exporting function 'New-DSCCheckSum'.
VERBOSE: Exporting function 'ThrowError'.
VERBOSE: Exporting function 'Write-Log'.
VERBOSE: Exporting function 'WriteFile'.
VERBOSE: Exporting function 'ReadEnvironmentFile'.
VERBOSE: Exporting function 'Get-DscResource'.
VERBOSE: Exporting function 'GetResourceFromKeyword'.
VERBOSE: Exporting function 'GetCompositeResource'.
VERBOSE: Exporting function 'AddDscResourceProperty'.
VERBOSE: Exporting function 'AddDscResourcePropertyFromMetadata'.
VERBOSE: Exporting function 'GetSyntax'.
VERBOSE: Exporting function 'CheckResourceFound'.
VERBOSE: Exporting function 'GetImplementingModulePath'.
VERBOSE: Exporting function 'GetModule'.
VERBOSE: Exporting function 'IsHiddenResource'.
VERBOSE: Exporting function 'GetPatterns'.
VERBOSE: Exporting function 'IsPatternMatched'.
VERBOSE: Exporting alias 'sacfg'.
VERBOSE: Exporting alias 'tcfg'.
VERBOSE: Exporting alias 'gcfg'.
VERBOSE: Exporting alias 'rtcfg'.
VERBOSE: Exporting alias 'glcm'.
VERBOSE: Exporting alias 'slcm'.
VERBOSE: Exporting function 'Get-DscConfiguration'.
VERBOSE: Exporting function 'Test-DscConfiguration'.
VERBOSE: Exporting function 'Get-DscLocalConfigurationManager'.
VERBOSE: Exporting function 'Restore-DscConfiguration'.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
powershell - Suppressing VERBOSE for Import-Module
I'm importing Carbon into my PowerShell script; however when running my script with -Verbose, Carbon also outputs a lot of VERBOSE statements.
Read more >Import-Module (Microsoft.PowerShell.Core)
The Import-Module cmdlet adds one or more modules to the current session. Starting in PowerShell 3.0, installed modules are automatically imported to the ......
Read more >PowerCLI 6.5.x - Import-Module when executed via a...
PowerCLI 6.5.x - Import-Module when executed via an C# and ASP.net fails with command was found in the module but the module could...
Read more >Importing a PowerShell Module
In PowerShell 3.0, PowerShell is able to implicitly import a module when one of the functions or cmdlets in the module is called...
Read more >Write-PSFMessage | Welcome to the PowerShell Framework
Writes the message “Connecting to $computer” to verbose. Includes the variable $computer in the message. This has no effect on the text shown...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Tangent alert (may be of interest to some; I’m sharing it, because it baffled me initially):
The processing of
-Verbose:$falseis somewhat unusual in this case:Unless you take extra action, passing
-SomeSwitch:$falseand omitting-SomeSwitchare equivalent. The$SomeSwitchparameter variable will be a[switch]-typed variable whose.IsPresentproperty (a somewhat unfortunate choice of property name) is$Falsein both cases.From what I understand, that is the intent behind
-SomeSwitch:$false, which normally only exists to facilitate programmatic construction of a command line.The only way to distinguish these two cases is to do something like
$PSBoundParameters.ContainsKey('SomeSwitch')(or its C# equivalent in a compiled cmdlet), which is apparently what happens here (in PowerShell Core, where this issue’s problem does not happen any longer):$PSBoundParameters.ContainsKey('SomeSwitch')returning$Truedespite$SomeSwitch.IsPresentreturning$Falseimplies that-SomeSwitch:$Falsewas passed.Thus,
-Verbose:$falsefunctioning as a signal to override the$VerbosePreferencevariable (as opposed to having no effect, which is what seemingly happens in the current production versions) is a semantic anomaly, but it is helpful and documented.@MaximoTrinidad excellent point, I’ll update the readme