PowerShell

Another common challenge with DSC, is how to compose DSC configurations.

People have seen the trick of having a Configuration, and the following code within:


Configuration MyDSCConfig {
Node $ConfigurationData.AllNodes.nodename {
if($Node.roles -contains 'MyRole') {
# do stuff here, like calling DSC Resources
MyCompositeResource StuffForMyRole {
#
}
}
if($Node.roles -contains 'MyOtherRole') {
MyOtherResource OtherStuff {
#
}
}
}
}

view raw

MyDscConfig.ps1

hosted with ❤ by GitHub

This is a good way to get started and works well for small-ish configurations, but it gets out of hand pretty quickly, as it’s hard to read all the if statements and their content. Some variant of this are using Where clauses around the Node expression.

Read Full Article

Here’s a quick function to allow you something close to splatting with DSC resources:


function Get-DscSplattedResource {
[CmdletBinding()]
Param(
[String]
$ResourceName,
[String]
$ExecutionName,
[hashtable]
$Properties
)
$stringBuilder = [System.Text.StringBuilder]::new()
$null = $stringBuilder.AppendLine("Param([hashtable]`$Parameters)")
$null = $stringBuilder.AppendLine(" $ResourceName $ExecutionName { ")
foreach($PropertyName in $Properties.keys) {
$null = $stringBuilder.AppendLine("$PropertyName = `$(`$Parameters['$PropertyName'])")
}
$null = $stringBuilder.AppendLine("}")
Write-Debug ("Generated Resource Block = {0}" -f $stringBuilder.ToString())
[scriptblock]::Create($stringBuilder.ToString()).Invoke($Properties)
}
Set-Alias Name x Value Get-DscSplattedResource

Here’s why you may need it.

Read Full Article

This is the first article in a series that aim to explore one way of getting started with DSC Development, covering tools and workflow.

In very short and abstract, the life cycle of a Windows Server could look like:

  • Deployment (aka OSD)
  • Configuration
  • Maintenance
  • Decommission

This series aims to focus at the Configuration part, mainly in its development phase, but also covers the basics of creating windows Image for experimentation purposes. The idea is to get started experimenting quickly, but I would not use this approach of Image creation for something that needs to be maintained.

Read Full Article

I wanted write down somewhere what technical books I’ve read, or I want to read in future.

Here’s my list, please comment to suggest some more! A couple of them haven’t been released yet, but I want to grab them either when they’re released, or through MEAP.

Adding a few suggested by BenH following DSCCamp:

That’s all I have in mind at the moment, but my books are all stacked in a corner of the leaving room, waiting for the bookshelf to be built…

What do you think, anything worth adding?