PowerShell Desired State Configuration Error: Undefined Property ConfigurationName

The scenario in this blog article is that you’ve created a DSC configuration on a computer that’s running a preview of PowerShell version 5. The machine itself could be running Windows 8.1, Server 2012 R2, or the Windows Technical Preview version of Windows 10.

Here’s a simple configuration that I’ll use to demonstrate the problem. This DSC configuration uses a custom DSC resource to rename a computer. This configuration is being created on a machine running the Windows Technical Preview version of Windows 10 with PowerShell version 5 build 9860 (the most recent build as of this writing).

A new Windows 2012 R2 Server (running PowerShell v4) has been brought online and no configuration has been done to it so far. The IP address of that server is 192.168.29.107. That IP address has been added to the TrustedHosts on the Windows 10 workstation that is being used to create the DSC configuration.

The configuration is run and the MOF file is generated for the server as shown in the following example:

dsc-error1

An attempt to apply the configuration to the server is made, but an error is generated:

dsc-error2

Undefined property ConfigurationName
At line:16, char:2
Buffer:
onfigureNewServer”;
};^
insta
+ CategoryInfo : SyntaxError: (root/Microsoft/…gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MiClientApiError_Failed
+ PSComputerName : 192.168.29.107

Since I’m using a custom DSC resource that I wrote, you might think that the error has to do with it, but this error would occur even if one of the Microsoft supplied DSC resources was being used.

The issue is that there’s a couple of extra lines in the MOF files generated by a machine running PowerShell version 5 which seems to make the MOF files incompatible with a machine running PowerShell version 4.

The following MOF configuration file was created on a machine running PowerShell v5:

dsc-error3

Here’s the same MOF file created on a machine running PowerShell version 4:

dsc-error4

Removing those two lines allows the configuration to complete successfully without issue. For a single MOF file manually modifying it probably wouldn’t be an issue, but what if you had dozens or more? Then there’s the question as to why you would want to do anything manually that you could use PowerShell to automate? After all, that is the purpose isn’t it?

Here’s a function to remove those two lines from one or more MOF files:

The path to the files can be provided via parameter or pipeline input:

dsc-error5a

Now that those two lines have been removed from the MOF file, let’s try to apply the configuration again:

dsc-error6

Success!

µ

6 Comments

  1. FoxDeploy

    Mike, if both machines are running PS v5, does this still come up?

    Reply
  2. Jeffery Hicks (@JeffHicks)

    Good detective work. For now, I think the best practice is not to mix PowerShell versions with DSC.

    Reply
  3. R Alladi

    Mike, I’m experimenting with DSC to install SQL Server. I am running into the error ‘Undefined DSC Resource’. I have the xSQLServer resource in the $env:PSModule path. Get-DSCResource shows xSQLServer but Get-Module doesn’t bring up any of the modules associated with it. I am on Windows 2012 R2 with PS 4.0. Any ideas, please?

    Reply
  4. Luc F

    Hello Mike,

    Thank you for this explanation.
    I am currently using the released version 5.
    It seems like there are some additional lines to be removed :

    MinimumCompatibleVersion = “1.0.0”;

    and

    CompatibleVersionAdditionalProperties=

    I have adapted your script with those lines to remove and it works fine for me.

    Reply

Leave a Reply

%d bloggers like this: