question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import-Module cmdlet doesn't respect -Verbose:$false switch

See original GitHub issue

You 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:closed
  • Created 6 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
mklement0commented, Jun 30, 2017

Tangent alert (may be of interest to some; I’m sharing it, because it baffled me initially):

The processing of -Verbose:$false is somewhat unusual in this case:

Unless you take extra action, passing -SomeSwitch:$false and omitting -SomeSwitch are equivalent. The $SomeSwitch parameter variable will be a [switch]-typed variable whose .IsPresent property (a somewhat unfortunate choice of property name) is $False in 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 $True despite $SomeSwitch.IsPresent returning $False implies that -SomeSwitch:$False was passed.

Thus, -Verbose:$false functioning as a signal to override the $VerbosePreference variable (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.

2reactions
SteveL-MSFTcommented, Jul 5, 2017

@MaximoTrinidad excellent point, I’ll update the readme

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found