PowerShell DSC Journey – Day 8

Alright. Picking up where I left off yesterday, this time I am seriously going to work on the Get, Test and Set Functions for my first custom DSC Resource. I promise I won’t get myself sidetracked by why I need the full path to import my Module :).

First things first, here is the code that was generated by the DSC Resource Designer for the Get-TargetResource Function.

Off the top of my head, some things I need to do: Ensure SCVMM Cmdlets exist. Make sure the VMM Server is valid. See if the Hardware Profile name already exists, if so, return the appropriate values. I am also going to add regions to each section of this script so that they can be easily collapsed when working on other sections.

First task, lets make sure that the SCVMM cmdlets exist and are available. I pretty much took this section and modified it from the xVMHyper-V Resource.

And if I run this on my desktop, I don’t get any kind of error which is what it should do. Now let me copy and paste this into a VM that doesn’t have the SCVMM cmdlets and this happens.

Well, that was easy enough :). Next thing, let’s make sure that the $VMMServer is an actual VMMServer. I start out by doing this (for testing purposes to see if this is going to work).

Followed by this (because I want to see what the output type is).

The name property is a string like the $VMMServer parameter is, so I should be able to just compare them and call it good.

That looks good. Now, I change my $VMMServer variable to MY-VMM-SERVER2 run it again and this happens.

This is obviously an issue because I already stored a value in there, something that would not happen (more than likely) when someone runs this Configuration. So, let’s just clean it out quick and try this again.

And now when I run my little test I get this for the output.

So, now that we know that works, let me write this in a way that actually makes sense and can be useful.

Next, let me check and see if the SCVMM Hardware Profile exists. For right now I am only concerned with using an existing SCVMM Hardware Profile. I will cross the bridge of creating a new Hardware Profile later. This is where things are going to get interesting, so I am going to save this for the next blog post 🙂