dsccommunity / xPSDesiredStateConfiguration

DSC resources for configuring common operating systems features, files and settings.
https://dsccommunity.org
MIT License
203 stars 132 forks source link

Need to Suppress or Resolve: The 'Microsoft.PowerShell.Management' module was not imported because the 'Microsoft.PowerShell.Management' snap-in was already imported. #611

Open mhendric opened 5 years ago

mhendric commented 5 years ago

Details of the scenario you tried and the problem that is occurring

The Integration test logs are full of the below Warning messages. In the most recent Integration test job, there were 189 instances of this. This does not occur in the Unit tests however. This also does not occur when I run the Integration tests on my own Windows 2019 machine.

The 'Microsoft.PowerShell.Management' module was not imported because the 'Microsoft.PowerShell.Management' snap-in was already imported.

Verbose logs showing the problem

A bigger example from https://ci.appveyor.com/project/PowerShell/xpsdesiredstateconfiguration/builds/23613517/job/7ec82b42naour8iy:

[00:02:00]   Describing MSFT_xDSCWebService_Integration
[00:02:00] 
[00:02:00]     Context When using configuration MSFT_xDSCWebService_PullTestWithSecurityBestPractices_Config
[00:02:01] The 'Microsoft.PowerShell.Management' module was not imported because the 'Microsoft.PowerShell.Management' snap-in was already imported.
[00:02:03]       [+] Should compile and apply the MOF without throwing 2.94s
[00:02:04]       [+] Should be able to call Get-DscConfiguration without throwing 178ms
[00:02:04]       [+] Should return $true when Test-DscConfiguration is run 78ms
[00:02:04] The 'Microsoft.PowerShell.Management' module was not imported because the 'Microsoft.PowerShell.Management' snap-in was already imported.
[00:02:06]       [+] Should compile and apply the MOF without throwing 2.65s
[00:02:07]       [+] Should be able to call Get-DscConfiguration without throwing 188ms
[00:02:07]       [+] Should return $true when Test-DscConfiguration is run 273ms
[00:02:07]       [+] Should create a web.config file at the web site root 9ms
[00:02:08]       [+] Should create a firewall rule for the chosen port 1.17s
[00:02:08] The 'Microsoft.PowerShell.Management' module was not imported because the 'Microsoft.PowerShell.Management' snap-in was already imported.
[00:02:09]       [+] Should compile and apply the MOF without throwing 1.29s
[00:02:09]       [+] Should be able to call Get-DscConfiguration without throwing 56ms
[00:02:09]       [+] Should return $true when Test-DscConfiguration is run 66ms
[00:02:09] 

Suggested solution to the issue

I'm unsure of how to fix this. Would appreciate community assistance.

Version of the DSC module that was used ('dev' if using current dev branch)

dev

tmeckel commented 5 years ago

@mhendric The documentation about compiling resources for Azure Automation DSC states the following

When compilation is complete you may receive an error stating: The 'Microsoft.PowerShell.Management' module was not imported because the 'Microsoft.PowerShell.Management' snap-in was already imported. This warning can safely be ignored.

https://docs.microsoft.com/en-us/azure/automation/automation-dsc-compile#assets

If you do ask Google about this you'll find numerous places where this issue is mentioned and as far as I can tell (also by taking into account the stuff that I found via Google) the warning will be issued when you compile a DSC configuration. My guess is confirmed by the fact that after such a warning you'll always find a Pester statement about Should compile blahblah. Interesting is that this warning does not appear if you compile a DSC configuration interactively in a PowerShell session, what you already mentioned.

So I think to have this (really annoying!!!) warning fixed you must get in touch with the people who maintain the DSC core infrastructure. I think @kwirkykat @johlju or @PlagueHO can help here.