PowerShell Desired State Configuration (DSC) Journey – Day 13

When we left off last week I was messing around with the Log resource and found out some interesting things about the Package resource and non MSI application installation.

Today I am going to explore using the Archive and Environment resources.  I am getting a little adventurous here attempting to tackle two at a time but I feel like I am confident enough with the DSC Resources at this point that it shouldn’t be an issue.

First up is the Environment Resource.  The Environment Resource has the Properties Name, DependsOn, Ensure, Path, and Value.  Only Name is mandatory.  Which is interesting.  I don’t know why you would Name an Environmental Variable and then not set anything else for it.  Everything is pretty self explanatory except for the Path Property.  The TechNet article says this about the Property.  “Defines the environment variable that is being configured. Set this property to $true if the variable is the Path variable; otherwise, set it to $false. The default is $false. If the variable being configured is the Path variable, the value provided through the Value property will be appended to the existing value.”  So, let’s test this both ways, with the path variable both $true and $false.

Here is the code I have added to my ServerConfig Configuration.

So, if this does what I want it to, it should add C:\Scripts to the $path variable on DSCTest as well as add an environmental variable for C:\Scripts.  Here is what I have currently for my $env:Path variable.

I Invoke the Configuration and go to run the Scheduled Task to force a Pull and once again it’s running.  And has been since Friday night basically.  Awesome.  Is anyone else seeing this kind of behavior from the Scheduled Task?

Anyways, after the reboot the DSCRestartBootTask completed successfully.  However, the $env:path variable doesn’t have C:\Scripts listed.  However, this did happen.

Well, that’s not what was supposed to happen.  Seems pretty clear.  “Set this property to $true if the variable is the Path variable; otherwise, set it to $false. If the variable being configured is the Path variable, the value provided through the Value property will be appended to the existing value.”  Lies!  Let’s try using the Program Files directory and see if that works.  And yes, the C:\Scripts does exist, my Configuration script ensures that :).

No dice.  It did this instead, since I didn’t delete the Environmental Variables I created previously, which is good to know.

dsc23

Alright, that didn’t work.  So.  Uh.  I guess let’s just try it without the Ensure value.  Which shouldn’t matter at all, but let’s try it anyways.  I change my code to this, and try it again.

And not surprisingly it just added it to the System Variables list.  I am going to try something really wacky before I head to Google to see what is out there about this.

Then, I have an idea.  An idea that makes me feel dumb, but I do it and share it with you anyways.

Nope, not even that did the trick.  I thought for sure that removing the $True from within double quotes would do the trick.  That maybe since DSC couldn’t recognize the bool value inside of quotes it was just defaulting to $False.  I add the Ensure = “Present” line to the code and try that.  Nope.  Still just adds a new environmental variable.

At this point I am completely out of ideas, and Google is no help on this issue at all.  I am probably doing something wrong but I have no idea what it is.  Any suggestions are more than welcome 🙂 .  Looks like the Archive resource is going to have to wait until tomorrow.