Skip to content

Invalid MOF definition when having an Instance[] #128

@raandree

Description

@raandree

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

Reproduction of the issue was done with the resource DnsServerRootHint in DnsServerDsc.

When passing values to a parameter defined as array and `EmbeddedInstance("MSFT_KeyValuePair")], compiling the following configuration.

This issue is related to #126.

ipmo PSDesiredStateConfiguration -Force

$rootHints = @{
    'A.ROOT-SERVERS.NET.' = '2001:503:ba3e::2:30'
    'B.ROOT-SERVERS.NET.' = '2001:500:84::b'
}

configuration RootHintsConfig {
    Import-DscResource -ModuleName DnsServerDsc

    DnsServerRootHint xRootHints
    {
        IsSingleInstance = 'Yes'
        NameServer       = $rootHints
    }
}

results in this invalid MOF file. Note that the parameter NameServer is an array but it is lacking the curly braces.

/*
@TargetNode='localhost'
@GeneratedBy=randr
@GenerationDate=08/11/2025 22:39:07
@GenerationHost=RAANDREE1
*/

instance of MSFT_KeyValuePair as $MSFT_KeyValuePair1ref
{
Key = "B.ROOT-SERVERS.NET.";
 Value = "2001:500:84::b";

};

instance of MSFT_KeyValuePair as $MSFT_KeyValuePair2ref
{
Key = "A.ROOT-SERVERS.NET.";
 Value = "2001:503:ba3e::2:30";

};

instance of DSC_DnsServerRootHint as $DSC_DnsServerRootHint1ref
{
IsSingleInstance = "Yes";
 ResourceID = "[DnsServerRootHint]xRootHints";
 ModuleVersion = "3.0.0";
 SourceInfo = "D:\\Git\\CommonTasks\\tests\\x.ps1::11::5::DnsServerRootHint";
 NameServer =    $MSFT_KeyValuePair1ref,
   $MSFT_KeyValuePair2ref
;
 ModuleName = "DnsServerDsc";

 ConfigurationName = "RootHintsConfig";

};
instance of OMI_ConfigurationDocument


                    {
 Version="2.0.0";


                        MinimumCompatibleVersion = "1.0.0";


                        CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};


                        Author="randr";


                        GenerationDate="08/11/2025 22:39:07";


                        GenerationHost="RAANDREE1";


                        Name="RootHintsConfig";


                    };

A correct MOF file would look like this:

/*
@TargetNode='localhost'
@GeneratedBy=randr
@GenerationDate=08/11/2025 23:00:24
@GenerationHost=RAANDREE1
*/

instance of MSFT_KeyValuePair as $MSFT_KeyValuePair1ref
{
Key = "A.ROOT-SERVERS.NET.";
 Value = "2001:503:ba3e::2:30";

};

instance of MSFT_KeyValuePair as $MSFT_KeyValuePair2ref
{
Key = "B.ROOT-SERVERS.NET.";
 Value = "2001:500:84::b";

};

instance of DSC_DnsServerRootHint as $DSC_DnsServerRootHint1ref
{
SourceInfo = "D:\\Git\\CommonTasks\\tests\\x.ps1::11::5::DnsServerRootHint";
 ModuleVersion = "3.0.0";
 NameServer = {
       $MSFT_KeyValuePair1ref,
   $MSFT_KeyValuePair2ref

};
 IsSingleInstance = "Yes";
 ModuleName = "DnsServerDsc";
 ResourceID = "[DnsServerRootHint]xRootHints";

 ConfigurationName = "RootHintsConfig";

};
instance of OMI_ConfigurationDocument


                    {
 Version="2.0.0";


                        MinimumCompatibleVersion = "1.0.0";


                        CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};


                        Author="randr";


                        GenerationDate="08/11/2025 23:00:24";


                        GenerationHost="RAANDREE1";


                        Name="RootHintsConfig";


                    };

Expected behavior

Correct MOF file to be creaetd.

Actual behavior

MOF file has a syntax error.

Error details

PSMessageDetails      : 
Exception             : System.InvalidOperationException: Invalid MOF definition for node 'localhost': Exception 
                        calling "ValidateInstanceText" with "1" argument(s): "Syntax error: 
                         At line:26, char:40
                         Buffer:
                         $MSFT_KeyValuePair1ref,^
                           $M
                        "
TargetObject          : 
CategoryInfo          : InvalidOperation: (:) [Write-Error], InvalidOperationException
FullyQualifiedErrorId : InvalidMOFDefinition,Write-NodeMOFFile
ErrorDetails          : Invalid MOF definition for node 'localhost': Exception calling "ValidateInstanceText" with 
                        "1" argument(s): "Syntax error: 
                         At line:26, char:40
                         Buffer:
                         $MSFT_KeyValuePair1ref,^
                           $M
                        "
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Write-NodeMOFFile, D:\Git\CommonTasks\output\RequiredModules\PSDesiredStateConfiguration\2 
                        .0.7\PSDesiredStateConfiguration.psm1: line 2954
                        at Configuration, D:\Git\CommonTasks\output\RequiredModules\PSDesiredStateConfiguration\2.0.7 
                        \PSDesiredStateConfiguration.psm1: line 2236
                        at <ScriptBlock>, D:\Git\CommonTasks\tests\x.ps1: line 8
                        at <ScriptBlock>, D:\Git\CommonTasks\tests\x.ps1: line 18
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 0}

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

Crescendo?

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions