Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Cannot Import PSDscResources #81

Closed
SylvainMartel opened this issue Jul 20, 2017 · 20 comments
Closed

Cannot Import PSDscResources #81

SylvainMartel opened this issue Jul 20, 2017 · 20 comments

Comments

@SylvainMartel
Copy link

I have the same issue as was described in #47 . But I'm not using any insider build

Name                           Value
----                           -----
PSVersion                      5.1.14409.1005
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1005
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

As soon as I install PSDscResources, I am not able to compile any mof anymore(wheter I try to load PSDscResources or not), I always get the error

ImportClassResourcesFromModule : Exception calling "ImportClassResourcesFromModule" with "3" argument(s): "Resource name 'WindowsPackageCab' is already being used by another Resource or
Configuration."
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2109 char:35
+ ... rcesFound = ImportClassResourcesFromModule -Module $mod -Resources $r ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ImportClassResourcesFromModule], MethodInvocationException
    + FullyQualifiedErrorId : PSInvalidOperationException,ImportClassResourcesFromModule

The server is a Windows 2012 R2

@mbreakey3
Copy link
Member

Did you make sure you have all the latest windows updates? This looks like a very similar case/environment as issue #43, and installing all of the latest patches fixed his issue.

@mbreakey3
Copy link
Member

Let me know if you're still having problems after checking this

@SylvainMartel
Copy link
Author

SylvainMartel commented Jul 20, 2017

Perusing the issue, I see that the patch that might solve this was never identified. Since I am on a corporate network, many patches are not deployed if the security team thinks they are not warranted, but if the right patch is identified, I can ask for it to be installed. Anyone managed to identify the patch required? A quick search on google didn't give any clue either.

As extra information, I have also tried installing PSDscResources on a test Windows 2016 server(using Install-Module PSDscResources) , and as soon as it's there, the problem appear too, even if I do not try to load PSDscResources.

@SylvainMartel
Copy link
Author

I also tried the solution listed here: https://msdn.microsoft.com/en-us/powershell/wmf/5.0/limitation_dsc
but the result stays the same.

Import-DscResource -ModuleName @{ModuleName='PSDscResources';RequiredVersion='2.8.0.0'}

@mbreakey3
Copy link
Member

I'm not sure which patch fixes this issue, but if possible, I would certainly recommend updating your machine.
As for the 2016 machine, what is the PowerShell version installed on that machine?

@SylvainMartel
Copy link
Author

SylvainMartel commented Jul 21, 2017

Windows 2016 PS version. Strange, it looks older than the WMF 5.1 we downloaded for Win2012R2. But afaik, there are no WMF 5.1 download available for Win2016 so I guess this is the most recent version for that OS.

Name                           Value
----                           -----
PSVersion                      5.1.14393.206
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.206
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

As for updating the 2012R2 server: I'd love to. But in our corporate environment, I have no control over that unless I open a problem in the internal ticketing. But if I can't give them a hint of what kb to look at, I already know it will stay open forever. I'll try to search some more to see if I find some related KB.

@mbreakey3
Copy link
Member

Do you know if there's any Windows updates for the 2016 machine? I apologize for the inconvenience this is causing. We had to make some significant changes to our system in order for this module to work since the resource names are the same as in PSDesiredStateConfiguration, so we depend on the machines have the most recent updates.

@SylvainMartel
Copy link
Author

It might be easier for Windows 2016 since it looks like there are only cumulative updates for that OS, so the security team can't get picky about what to install. I'll ask for the latest to be installed on my test machine and report back.

@SylvainMartel
Copy link
Author

SylvainMartel commented Jul 24, 2017

We installed the latest cumulative update on Windows 2016(KB4025334), rebooted, and sadly the problem is still there. The powershell version changed to:

Name                           Value
----                           -----
PSVersion                      5.1.14393.1532
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1532
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

But still, as soon as we install PSDscResources, we cannot compile mof's anymore, even if we do not try to load PSDscResources inside the configuration.

@mbreakey3
Copy link
Member

Okay, I'll look into this further and get back to you as soon as I can.

@kwirkykat
Copy link
Member

@kinwolfqc There must be something else happening in your environment or configuration that is causing this conflict.
I have confirmed that PSDscResources works/does not work in these WMF versions:

PsDscResources does not work
5.1.15063.296 -- WMF 5.1 in Windows 10 Creators Update prior to 6/16/17
5.1.15063.0 -- WMF 5.1 in Windows 10 Creators Update
5.1.15055.0 -- WMF 5.1 in a past Windows Insider Update
5.1.14394.1000 -- WMF 5.1 preview version
5.0 or below

PsDscResources works
5.1.14393.953 -- version out on Windows 10/Windows Server 2016 BEFORE Creators update
5.1.14409.1005 -- downloadable WMF 5.1
5.1.15063.413 -- current version out on Windows 10 as of 6/16/17

I've tested with WMF 5.1.14409.1005 which is what you have on your Windows 2012 R2 machine and it works fine for me there.
I can't speak as confidently for the more recent versions of 5.1.14393, but I know 5.1.14393.953 worked, and as far as I know none of the problems with DSC in Windows 10 ever reached any version of Windows Server.

Did you install PSDscResources using Install-Module?

A possible (but it sounds like not probable) problem that could be occurring is that other module(s) is/are implicitly trying to import PSDesiredStateConfiguration and PSDscResources at the same time as dependencies. You can check the RequiredModules field in the module manifest (.psd1) file of any other modules you are importing in your configuration(s) to see if they are importing either of those modules as dependencies.

Could you share your configuration or maybe just the part of it where you call Import-DscResource?

You could also try just calling Import-Module PSDesiredStateConfiguration and Import-Module PSDscResources to see if the modules themselves will even import outside a configuration (they should if everything is working correctly).

It could also be some bizarre problem with your PSModulePath. Though I'm not really sure how.

Have you tried a different, very basic configuration like configuration myconfig { Import-DscResource -ModuleName PSDesiredStateConfiguration } on the same machine?

The specific function you are having a problem with is actually in PowerShell itself, not in DSC, so you can see their most recent code for the function throwing the error in their open source code here: https://github.com/PowerShell/PowerShell/blob/ffd39b2853b68419eb0fd5e34a89b755c98b8022/src/System.Management.Automation/DscSupport/CimDSCParser.cs#L2180 (But keep in mind that code is for PowerShell Core and not the exact version of PowerShell you are using)

@SylvainMartel
Copy link
Author

SylvainMartel commented Jul 28, 2017

I did what you proposed, starting with a new basic configuration, and I added stuff in it until it broke. Doing so, I was able to find the problem, but not the solution:
We use composite resources to keep the main script manageable, and to be able to reuse the code we put in the composite resource in other configurations. As soon as we import a composite resource, we get the error message. But I looked into the manifests of the composite resource and nowhere does it load, or ask for, PSDesiredStateConfiguration, or any other modules for that matter.

So I did another test, I created a completely new, and empty, composite resource and as soon as I tried to import it(while PSDscResources 2.8.0.0 was present) I got the dreaded

ImportClassResourcesFromModule : Exception calling "ImportClassResourcesFromModule" with "3" argument(s): "Resource name 'WindowsPackageCab' is already being used by another Resource or
Configuration."
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2109 char:35
+ ... rcesFound = ImportClassResourcesFromModule -Module $mod -Resources $r ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ImportClassResourcesFromModule], MethodInvocationException
    + FullyQualifiedErrorId : PSInvalidOperationException,ImportClassResourcesFromModule

So could it be a bug related to the way composite resources are called/used?

@SylvainMartel
Copy link
Author

SylvainMartel commented Jul 28, 2017

I use this script from Ashley McGlone to create composite resource manifests and it's basic files quickly
https://gallery.technet.microsoft.com/Helper-Function-to-Create-bf248c68

@SylvainMartel
Copy link
Author

Any update on this? Right now it seems we are offered two choices: Either use Composite Resource and not be able to update the original PSDscResource, or be able to update PSDscResource and forego using Composite Resources(which makes our configurations pretty much unmanageable so much they get big)

@kwirkykat
Copy link
Member

kwirkykat commented Sep 7, 2017

@kinwolfqc I tried out using PSDscResources along with some custom composite configurations and it all works fine for me. PSDscResources itself has several composite resources as well (all the *Set resources). So it doesn't seem to be a problem within PSDscResources.

What about in the .schema.psm1 files of the composite resources? They don't import any modules or DSC resources there either?

@kwirkykat
Copy link
Member

kwirkykat commented Sep 7, 2017

@kinwolfqc I just figured it out. Somewhere in your code or on your machine, something is calling Import-Module PSDscResources instead of Import-DscResource -Module PSDscResources. The first one results in the error you gave. The second one works fine. You shouldn't ever have to directly import PSDscResources with Import-Module. In all your configurations and composite resources you can just call Import-DscResource -Module PSDscResources.

@SylvainMartel
Copy link
Author

SylvainMartel commented Sep 8, 2017

@kwirkykat Holy guacamole! What you describe wasn't the case for us, as we only use Import-DscResource -Module PSDscResources -ModuleVersion 2.8.0.0 , but it did give me a hint.

Here was the line that was loading the custom resource, and gave the error:

Import-DscResource -Module xActiveDirectory, DSQCompositeResources
Import-DscResource -Module PSDscResources -ModuleVersion 2.8.0.0

(AFAIK loading more than one module on one line was always allowed as it never caused us any problem until we tried also loading PsDscResources)

Here is the simple fix making it all work:

Import-DscResource -Module xActiveDirectory
Import-DscResource -Module DSQCompositeResources
Import-DscResource -Module PSDscResources -ModuleVersion 2.8.0.0

I guess DSC does something funny to the second or third module it tries to load when we use simple commas instead of repeating the whole "Import-DscResource" line?

Thanks a million for your time. We can now use the newer PSDscResources

@dazinator
Copy link

dazinator commented Apr 9, 2018

I just hit this same bug. I am running the DSC script on a windows docker container:

FROM microsoft/mssql-server-windows-developer:2017-latest

@kinwolfqc suggestion of changing to one Import-DscResource per line has fixed it..
How come this is necessary though? Won't it continue to catch others out?

@rdtechie
Copy link

Just encountered the same bug. When trying to import PSDesiredStatedConfiguration and some other DSC resources with a oneliner, I receive a error message like the one in the start of this issue. When changing to import one at a time, I don't receive the error and import succeeds.

@aut0pil0t
Copy link

@kwirkykat Holy guacamole! What you describe wasn't the case for us, as we only use Import-DscResource -Module PSDscResources -ModuleVersion 2.8.0.0 , but it did give me a hint.

Here was the line that was loading the custom resource, and gave the error:

Import-DscResource -Module xActiveDirectory, DSQCompositeResources
Import-DscResource -Module PSDscResources -ModuleVersion 2.8.0.0

(AFAIK loading more than one module on one line was always allowed as it never caused us any problem until we tried also loading PsDscResources)

Here is the simple fix making it all work:

Import-DscResource -Module xActiveDirectory
Import-DscResource -Module DSQCompositeResources
Import-DscResource -Module PSDscResources -ModuleVersion 2.8.0.0

I guess DSC does something funny to the second or third module it tries to load when we use simple commas instead of repeating the whole "Import-DscResource" line?

Thanks a million for your time. We can now use the newer PSDscResources

I just hit the same bug with Azure DSC as well. 🍡

X-Guardian pushed a commit to X-Guardian/PSDscResources that referenced this issue Jun 4, 2019
Fix Get-ModuleScriptResourceNames - Fixes PowerShell#81
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants