Managing DSC Resources in PowerShell Desired State Configuration (DSC)

image_thumb.png

PowerShell Desired State Configuration (DSC) Resources are an evolved type of function usually created by experienced PowerShell coders. Resources are at the very core of DSC and contain the code required to perform the actual configuration tasks in your deployments.

My first post was how to use DSC. My second post was about what DSC is, this post is more of a where to find and discover resources.

In my previous post, I used a DSC Resource called File and executed it a number of ways to manipulate a text file. You can view its syntax in the console by using the Get-DSCResource cmdlet with the -Syntax switch.

image

Built in Resources

DSC comes with a small number of built-in Resources for configuring files and folders, roles and features, security groups, registry settings, environment variables, and services and processes. You can view these built in resources by typing Get-DSCResource. This screenshot of my laptop, this is an example of what you would see with the default setup.

image

You can find more information on these build-in resources here: Built-In Windows PowerShell Desired State Configuration Resources

Powershell Team Resources

From December 2013 to February 2015 the PowerShell team released a number of DSC Resources called the DSC Resource Kit. These contained a number of PowerShell modules that contained DSC resources and example configurations. They were published to Technet in the PowerShell gallery.

These were great resources but were by no means complete. They were starter modules intended as guidance and working examples to help the community develop their own resources.

Sadly the PowerShell team have stopped publishing the resource kit at wave 10. They are however, still releasing new and updated resources via the PowerShell Gallery and recommend that you use PowerShellGet (in WMF 5.0) to find them.

Microsoft propose naming standards for publicly shared resources. They use the x prefix that stands for ‘experimental’. Microsoft Resources

No refunds!

These resources are offered freely but without any support. If you find any issues etc you can post a request on Microsoft Connect but don’t hold your breath. I posted a request last September that has had no response. Bugs however are answered slightly quicker like this one. DSC: xIPAddress IP detection issue I’ve still not seen a fix though. In the end I just fixed the bug myself and renamed the resource to a comunity resource using the standards Microsoft suggest at the bottom of this page.

Community resources

Speaking of which, you can develop your own resources or download them from the community. I’ll be releasing my own resources shortly in a kit to help automate the building of the Windows Server 2012 R2 Test Lab Guide.

ScriptimusExMachina Resources

Microsoft suggest prefixing your own resources with ‘c’ for community. If you do build your own resource then the PowerShell Team have posted the really helpful PowerShell DSC Resource Design and Testing Checklist on their blog. Thanks guys!

Corporate or private resourses.

You could create your own internal corporate standard. Eg. ‘e’ for enterprise. This would help to indicate that these are private and should not leave your business environment. But then again, that’s your own business.

Installing resources from the internet.

The first thing to do is (after a virus/malware scan) right-click and unblock the archive before accessing it as it came from the internet. If not then the contents will also be still blocked and you’ll have fun unblocking each of the files in turn.

Unblock

As always never put code from the internet into your production environments. Use the online resources as examples to help develop your own code.

Unpack the contents into the folder C:\Program Files\WindowsPowerShell\Modules\

Then use Get-DSCResource to see if you can now access them. If you can still only see the built in resources then it’s likely that you will need to download and install Hotfix KB 2883200 (Windows 8.1 and Windows Server 2012 R2 General Availability Update Rollup)

This is the last of the basic topics that I’ll be posting on DSC.  Next I’ll share the resources that have helped me learn DSC and then I’ll post details of the hurdles and gotcha’s I came across when trying to build my own resource.

Advertisements

About Andrew Barnes

A Scripting and Deployment Specialist.
This entry was posted in Deployment, Desired State Configuration, DSC, PowerShell and tagged , , , , . Bookmark the permalink.

3 Responses to Managing DSC Resources in PowerShell Desired State Configuration (DSC)

  1. Hi Andrew,
    I see you’ve written a DSC Resource cADGroup. I tried my hand also at making the very same! here’s the link http://goo.gl/70Dw80. How do you go about placing you code? Will it be accessible via GitHub also? Or will you publish via PowerShell gallery? Who validates code in PowerShell gallery? Looking forward to the next article!!!

    Rg./Irwin

    Like

    • Good questions Irwin. I still need to consider where to publish my DSC stuff. I’m not sure who validates the publish content to the PowerShell Gallery either.

      See that? I’m confident enough to say I just don’t know everything.

      Like

      • I’ve only signed up to GitHub a month ago. I’ve been using my own private subversion server on my Synology NAS. Prior to that I used to use Team Foundation. GitHub is looking like the way forward to share code. Especially now we have oneget etc.

        Also, although I’ve advocated the DSC checklist above, I’m still going through my code polishing it up and applying the practices. 😉

        Liked by 1 person

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