PowerShell DSC Journey – Day 12

Before I get started working on the Set-TargetResource function, it occurred to me over the weekend that instead of using $Name -cin $HWProfile.Name I should be using $Name -match $HWProfile.Name because otherwise I could just put a name like “Web” and who knows what would happen. Probably not anything good.

So, I make that change and run my first test using a valid Hardware Profile name and of course it fails. Of course!

After verifying that the Hardware Profile didn’t get deleted I think that match probably doesn’t do what I think it does. Reading through the about_comparison_operators help file I think that I need contains and contained in. So let’s make this change and try again. It also doesn’t work, and after doing some testing, it appears I need to reverse my comparison.

Awesome!

Now, let’s move along to the entire point of this post. Alright, so we need all of our checks and things we used previously (I think? I mean shouldn’t it just bomb out on Test and Get and never reach Set anyways?). I will stick them in there anyways especially since I know they work.
So here is what I have after doing that.

First thing I notice is the DependsOn parameter. I don’t see this parameter listed in any of the existing Resources anywhere, so I am just going to remove it from the Set-TargetResource. The only thing I need to Set right now is the Hardware Profile name if it doesn’t exist, so I will need to modify one section of the script here.

And…I think that is it for now. So let’s test this baby out and see how much red text I get.
Test 1:

That was expected. This test is where things are going to get real. For the second time in two days I feel like a DSC Wizard!

So pumped. I verify that it does in fact show up in the VMM GUI. I won’t bore you with the picture but I promise you that it is there. Now I will run my last test just for the sake of consistency.

For right now I am OK with it trying to check the HardwareProfile even if it can’t find the VMM server, but I will probably end up adding in more logic for testing that better at some point.

Well. I have a somewhat functioning (but not very useful) Custom Resource now. Tomorrow we will start adding in more Hardware Profile parameters!