Custom cAppPool Resource for DSC

Update: My cAppPool has been merged into the offical PowerShellOrg DSC repo on GitHub!

I'm still working furiously on a Desired State Configuration setup for a client.  One of the things I really like about PSDSC is that it is extensible and customizable, in fact that is one of the things I really like about PowerShell.  If you ever want to know how a cmdlet is working, you can go into the $PSPATH:Modules and check it out for yourself.  You can also create your own resources, modules, and script packages.  While working on the DSC project I found that I needed to customize a website and associate it with an AppPool.  No problem!  Microsoft has posted a WebAdministration resource for just such a task.  But the resource is still in development and does not have a portion to create and customize Application Pools.  So what did I do?  I created one.
In order to create a custom resource for PSDSC, you need to create three files (actually one is optional), and populate them with data.  The first is the schema.mof file, and it lives to define the inputs and outputs for your resource.  The second file is a descriptor file that references who wrote it, when they wrote it, and a bunch of other metadata.  The third file is the meat of your resource.  It must have three defined functions within it:
Test-TargetResource is the function that checks to see if the resource you are configuring complies with the settings you are submitting.  In the case of something simple like a file, this function would check to see if the file exists and return true if it does.  Get-TargetResource returns a hastable of all the properties specified in the resource.  If you specify a file name, destination path, and source path then this function would return a hashtable with those values.  The Set-TargetResource function is in charge of actually applying the desired configuration with the properties passed to it.  It doesn't return anything.

That's it.  Easy-peasy.  Microsoft has helpfully provided a custom resource development kit that will create the skeleton of these files for you given a list of DSC properties.  They also have some guidelines for naming that you ignore at your own peril.  I've posted the entire cAppPool resource on Github, and you can find it here.  Hopefully the main DSC branch will accept my Pull request and this will be part of the official community resources.

I used the skeleton of the xWebSite resource for my template, and in fact I have bundled the two together for use at the client.  There's still lots more to do and I am learning something new each day.  My next goal is to change the default Script resource to take local parameters.  In the meantime, I am using this workaround.

Labels: , , , ,