.psd is not .ps1

My first experiments with DSC consisted of a simple website that I wanted to deploy to a virtual machine I had running in Azure. Seems simple, doesn’t it? So I went ahead and created a DSC script and a file containing the configuration data, as described nicely on this blog: Separating “What” from “Where” in PowerShell DSC. So I ended up with two files: “Deploy.ps1” with my DSC configuration and “TestEnv.psd1” with the environment specific configuration data. Those two can be put together like so:

 
# Pass the configuration data to configuration as follows: 
Sample_xWebsite_FromConfigurationData -ConfigurationData TestEnv.psd1 

Where “Sample_xWebsite_FromConfigurationData” denotes the configuration as defined in the DSC script. When running this from a powershell prompt, it worked like a charm. Next step was to stick this in a vNext Release Template and run it from Release Management.

When configuring a vNext Release Template in Release Management, you’ll have to provide a “PSScriptPath” and “PSConfigurationPath” inside the “Deploy Using PS/DSC” block:

image

So I figured I’d provide the two files that I had prepared, one being the .ps1 file with the DSC configuration and the other being the .psd1 file with the configuration data. However, when running the deployment I got a bunch of weird errors, suggesting that my configuration data wasn’t passed to the DSC configuration. After doing some debugging I found that that was indeed the case.

Eventually I got the solution. Essentially: the “PSConfigurationPath” in Release Manager expects a regular Powershell script. So: a .ps1 file. If you supply a .psd1 file, Release Management will happilly run your deployment, but your configuration data will not be passed to your DSC configuration.

The solution is to put your configuration data in a variable, and pass that to your configuration. So, the DSC configuration looks something like this:

 
configuration Sample_xWebsite_FromConfigurationData {  	
  Node $AllNodes {
    ......  		
    # Copy the website content  		
    File WebContent 
    {
      Ensure = "Present"
      SourcePath = $Node.SourcePath
      DestinationPath = $Node.DestinationPath
      Recurse = $true
      Type = "Directory"
    }
    ...... 
  }
}
Sample_xWebsite_FromConfigurationData -ConfigurationData $configData

Notice the “$configData” parameter in the last line? That comes from the configuration data script:

# Hashtable to define the environmental data
$configData = @{
  # Node specific data
  AllNodes = @(
    @{
      NodeName = "*"
      WebsiteName = "FourthCoffee"
      SourcePath = "C:\BakeryWebsite\"
      DestinationPath = "C:\inetpub\FourthCoffee"
      DefaultWebSitePath = "C:\inetpub\wwwroot"
    }
  );
}

Make sure you save this as a .ps1 file! Then include it in your vNext Release Template in the “PSConfigurationPath” and all will be well!

Happy releasing!

Advertisements

One thought on “.psd is not .ps1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s