PowerShell DSC Journey – Day 14

When I left off yesterday, I had modified my Get-TargetResource to work (hopefully) with all the new properties I had setup for my Custom Resource. Now, I am going to test this, and DSC willing I will be able to move on to the Target Resource functions today before I finish this thing out.

First I am going to run my 3 previous tests that I knew worked and see if they still work. And…I am getting mildly competent at DSC it seems.

Alrighty then, on to Test 2. Still winning!

For Test 3 I am creating a new Test with the new Properties to see what happens. And halfway into writing this test I realize that is a dumb idea. It’s dumb because I already demonstrated above that with a valid Hardware Profile and a valid VMM Server name, I can return the current properties that I have setup. On to Test-TargetResource!

Ah. It’s in Test-TargetResource that I see all my additional properties show up.

While looking at what needed to be copied from the Get-TargetResource function I realized (maybe for the second time) that there was no reason for this section of code. So I got rid of it.

I looked at this for a while before trying out to figure out what to do. First thing I thought was that I need to modify the section that tests the Hardware Profile. Or something. This is really making my brain hurt. I should probably start doing these at the beginning of the day instead of at the end. Anyways, here is the Test-TargetResource Function in its entirety.

Well. Let’s fill the screen with red text.

Well that wasn’t red, but I certainly don’t want it to return False if the Hardware Profile exists so I add this change to the script. If($HWProfile -ne $Name){Return $False} . Run it again but I get the same error and it’s clear to me why. I haven’t specified the $Ensure parameter. So let’s try that out. Short version, that didn’t help, but that’s because I don’t have a DVD drive setting or anything else, so of course they are returning False. Duh. Dummy.

Let’s try this test, with the settings that I know are accurate.

Now we are talking. I am not going to bore you with a bunch more examples, but here is a summary of tests.
Ensure = Absent, Returns False
CPUCount = 4, Returns False
DVDDrive = False, Returns False
VMNetwork = Blah, Returns False
Name = Blah, Returns False

Today was a good day. Tomorrow it will be time for the Set-TargetResource Function.