PowerShell Desired State Configuration (DSC) Journey – Day 15

Yesterday I explored the Archive Resource.  Today I am going to look at the Role Resource.  When you look at Get-DSCResource it isn’t called Role.  It’s called WindowsFeature.  Make complete sense right?  Here are the expanded properties.

Alright.  Let’s do this.  You can find plenty of examples where people have installed one or two features using DSC.  Am I going to do that?  Absolutely not.  Let’s put this thing to the test.  To get a list of all the Windows Features available to install run this command.

Alright.  Let’s try to break some stuff.  Here is all the code that I added to my ServerConfig Configuration.  I immediately want to see if I can include multiple names in one Resource block.  I am also trying to break the LogPath Property.  It says to specify a path to a log file, so I am including a log file name in here so we will see what happens with that.

The Consistency scheduled task on DSCTest didn’t run nearly long enough for this to have worked.  Let’s go to the log and see what I broke.

And.  This is taking a long time to return anything.  That’s usually a sign that DSC itself is doing something.  Nope.  It came back right as I finished typing that.  Of course :).

Alright, it clearly didn’t like my Feature Names.  Let’s change the formatting a bit and try again.

It likes that even less (which completely makes sense, but I had to check!).  Here is the error.

Alright, let’s try this instead.

PowerShell ISE right away gives the second Name definition a squiggly which if you mouse over it plainly tells you that “Duplicate property resource definitions are not allowed in an instance definition”.  Well that certainly solves that.  Here is my new Configuration.

And the scheduled task is running.  While it is doing that, I am going to work on something else.  I imagine that’s going to take a while.

Checking back, I don’t see any of my Roles installed, but when I open the Add Roles and Features wizard it plainly tells me that the server has a pending restart.  Good sign!  I also check the C:\Scripts folder and see all of my specified text files in there, and it does look like everything ran.  Exciting stuff.

dsc26Time to reboot the server!  After the reboot, looking at the LocalConfigurationManager on DSCTest, it is set to reboot if needed, I wonder why it didn’t do that.  Or if I just didn’t wait long enough for it to reboot?  Either way, all the things got installed.

Now let’s install some IIS Management Tools and see if DSC will remove them.

I double check using Get-WindowsFeature and it is installed.  So let’s run our scheduled task and see if it gets removed.



If you are curious here is what my log file looks like when the IIS Management Tools were removed.

I am off tomorrow but I will pick back up next week.  I think it’s time for some more Custom Resources.  Hyper-V Anyone?