Search code examples
powershelldsc

How do I compile DSC to MOF if required module is not yet available


I need to use module xWebAdministration in my DSC Configuration but this module is not yet installed in system and being installed in Configuration preceding current one. Example is below. Also how do I use markdown with powershell code like below on StackOverflow. I put it into code blocks but there is no syntax highlighting.

Configuration BasicIIS
{
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration' 
    node localhost {
              ... Script etc logic which installed xWebAdministration Module
     }
}
BasicIIS -OutputPath .\BasicIIS
Start-DscConfiguration -Wait -Verbose -Path .\BasicIIS -Force
Configuration SecondStep
{
    Import-DSCResource -moduleName "xWebAdministration"
    xWebSiteDefaults DefaultConfig {
        ApplyTo = "Machine"
        LogDirectory = "c:\inetpub\logs\LogFiles\host"
        TraceLogDirectory = "c:\inetpub\logs\LogFiles\host\FREB"
    }
SecondStep -OutputPath .\BasicIIS
Start-DscConfiguration -Wait -Verbose -Path .\BasicIIS -Force

Solution

  • Unless you are in a Pull scenario (such as Azure DSC) you will need to pre-load module requirements. The easiest way to do this is publish your modules somewhere (NuGet service or file share) and run PowerShellGet before applying the config, or embed them in the image if a truly offline requirement.