Skip to content

A resource property with an empty array value does not land in the compiled MOF file #126

Open
@DoLearnWhileAlive

Description

@DoLearnWhileAlive

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

Running below configuration with PSDesiredStateConfiguration v2.0.7 in PowerShell produces a MOF file without the IPAddresses property. Using Windows PowerShell 5.1 instead a MOF file containing the IPAddresses property is created.

Configuration DnsServerForwarder_remove_config
{
    Import-DscResource -ModuleName 'DnsServerDsc'

    Node localhost
    {
        DnsServerForwarder 'SetForwarders'
        {
            IsSingleInstance = 'Yes'
            IPAddresses      = @()
            UseRootHint      = $false
        }
    }
}

Proposal

Lines 672-678 in PSDesiredStateConfiguration.psm1 should be changed from:

                    else
                    {
                        if ($targetTypeName -notmatch 'Array' -or $p.Value.Count)
                        {
                            $p.Name + ' = ' + (stringify -value $p.Value -asArray $asArray -targetType  $targetType ) + ";`n"
                        }
                    }

to

                    else
                    {
                        $p.Name + ' = ' + (stringify -value $p.Value -asArray $asArray -targetType  $targetType ) + ";`n"
                    }

Expected behavior

instance of DSC_DnsServerForwarder as $DSC_DnsServerForwarder1ref
{
ResourceID = "[DnsServerForwarder]SetForwarders";
 IPAddresses = {
};
 UseRootHint = False;
 SourceInfo = "::7::9::DnsServerForwarder";
 IsSingleInstance = "Yes";
 ModuleName = "DnsServerDsc";
 ModuleVersion = "3.0.0";

 ConfigurationName = "DnsServerForwarder_remove_config";

};

Actual behavior

instance of DSC_DnsServerForwarder as $DSC_DnsServerForwarder1ref
{
UseRootHint = False;
 SourceInfo = "::7::9::DnsServerForwarder";
 IsSingleInstance = "Yes";
 ResourceID = "[DnsServerForwarder]SetForwarders";
 ModuleVersion = "3.0.0";
 ModuleName = "DnsServerDsc";

 ConfigurationName = "DnsServerForwarder_remove_config";

};

Error details

Environment data

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

Version

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