Powershell DSC: Unable to load module xPSDesiredStateConfiguration
Asked Answered
O

2

8

I'm working through the DSC book from powershell.org and trying to setup a pull server using the configuration code specified in the book.

configuration CreatePullServer
{
    param
    (
        [string[]]$ComputerName = 'localhost'
    )

    Import-DSCResource -ModuleName xPSDesiredStateConfiguration

    Node $ComputerName
    {
        WindowsFeature DSCServiceFeature
        {
            Ensure = "Present"
            Name   = "DSC-Service"
        }

        xDscWebService PSDSCPullServer
        {
            Ensure                  = "Present"
            EndpointName            = "PSDSCPullServer"
            Port                    = 8080
            PhysicalPath            = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer"
            CertificateThumbPrint   = "AllowUnencryptedTraffic"
            ModulePath              = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
            ConfigurationPath       = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
            State                   = "Started"
            DependsOn               = "[WindowsFeature]DSCServiceFeature"
        }

        xDscWebService PSDSCComplianceServer
        {
            Ensure                  = "Present"
            EndpointName            = "PSDSCComplianceServer"
            Port                    = 9080
            PhysicalPath            = "$env:SystemDrive\inetpub\wwwroot\PSDSCComplianceServer"
            CertificateThumbPrint   = "AllowUnencryptedTraffic"
            State                   = "Started"
            IsComplianceServer      = $true
            DependsOn               = ("[WindowsFeature]DSCServiceFeature","[xDSCWebService]PSDSCPullServer")
        }
    }
}

CreatePullServer -ComputerName pull1.lab.pri

When I run the configuration script, powershell reports that it is unable to load the xPSDesiredStateConfiguration module.

Import-DSCResource -ModuleName xPSDesiredStateConfiguration Unable to load module 'xPSDesiredStateConfiguration': module not found.

I verified that I have the DSC resource kit installed, and the module is listed when I execute the Get-DSCResource command. Can anyone give me a clue as to what I may have done wrong?

Also, I am using Windows 7 64-bit and have installed KB2819745 to bring powershell up to version 4.

Opossum answered 2/10, 2014 at 14:22 Comment(3)
is the module availible on your system? Get-Module -ListAvailibleMorganica
Yes it is listed. Although your suggestion did lead me down the path to the solution. I noticed that when I ran the Get-Module -ListAvailable command it was listing the directory containing the module twice. While trying to solve an earlier problem I had added the $env:ProgramFiles\WindowsPowerShell\Modules directory to the PSModulePath environment variable, so the modules were duplicated somehow. It appears this was causing the problem, because it works after I removed the directory from the PSModulePath environment variable.Opossum
Mr.D wrote an Answer saying "you need to install the package, get this downloaded gallery.technet.microsoft.com/… this works for me"Fluker
O
10

Responding to a comment to my original question, I checked that the module was being listed when executing Get-Module -ListAvailable. I noticed that when I ran the command it was listing the directory containing the module twice. I then realized that while trying to solve an earlier problem I had added the $env:ProgramFiles\WindowsPowerShell\Modules directory to the PSModulePath environment variable, so the modules were being duplicated and causing problems. After removing the path from the PSModulePath environment variable, everything works!

Opossum answered 2/10, 2014 at 15:8 Comment(2)
Great! You should also accept this answer so that the question doesn't still appear unanswered.Folliculin
@PortlandRunner he's the original question author and answering his own question, which is encouraged at SO. Please pay attention, you recommended to delete a perfectly good answerJeannettajeannette
C
1

First, you need to install the package. You can download it from here:

https://gallery.technet.microsoft.com/xPSDesiredStateConfiguratio-417dc71d

Carlile answered 30/11, 2020 at 12:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.