Windows – How to debug Powershell Desired State Configuration not generating MOF files

dscpowershell-v4.0windows

I'm following the most basic example on MSDN and I'm failing to get it to work. I've got my configuration defined as follows:

Configuration MyWebConfig
{
   Param($ComputerName)

   Node $ComputerName {
      WindowsFeature MyRoleExample
      {
          Ensure = "Present"
          Name = "Web-Server"  
      }
    }
}

I'm trying to generate MOF with C:\Scripts> .\IisWithCompressionConfig.ps1 -ComputerName "localhost" -Outputpath C:\Scripts\localhost (and couple other command line variants). I'm not getting any file output and no errors are reported (exit status code is also 0). I've tried a version without the $ComputerName variable (and instead "localhost" hardcoded), still nothing. Yes, I'm running this in an elevated prompt.

I've made sure that I'm running PowerShell 4.0:

C:\Scripts> $PSVersionTable

Name                           Value                                                                                            
----                           -----                                                                                            
PSVersion                      4.0                                                                                              
WSManStackVersion              3.0                                                                                              
SerializationVersion           1.1.0.1                                                                                          
CLRVersion                     4.0.30319.34003                                                                                  
BuildVersion                   6.3.9600.16394                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}                                                                             
PSRemotingProtocolVersion      2.2

Any ideas what am I missing?

Best Answer

With DSC, I dot source the configuration definition into the current session, then call it.

# dot source will load PS1 into current session
. .\IisWithCompressionConfig.ps1
# Then call the config
MyWebConfig -ComputerName "localhost"

Configurations are quite similar to functions, that is you'd want to call MyWebConfig (config) not IisWithCompressionConfig (file). In fact, defined DSCs will be in the Function: PSDrive. Try running the following both before, and after, you dot source your PS1. Before, you should see no results, after, you should see MyWebConfig in the Function: PSDrive.

Get-ChildItem Function:* | Where-Object { $_.CommandType -eq 'Configuration' }

In the provided TechNet example, they're using the ISE. In step 4 they're defining (instead of sourcing) the MyWebConfig config right in the current PS session. This is functionally equivalent to dot sourcing the PS1 file. Right after step 6, they call MyWebConfig, which generated the MOF.