diff --git a/src/PSDesiredStateConfiguration/PSDesiredStateConfiguration.psm1 b/src/PSDesiredStateConfiguration/PSDesiredStateConfiguration.psm1 index 238d331..bd99473 100644 --- a/src/PSDesiredStateConfiguration/PSDesiredStateConfiguration.psm1 +++ b/src/PSDesiredStateConfiguration/PSDesiredStateConfiguration.psm1 @@ -671,10 +671,7 @@ function ConvertTo-MOFInstance } else { - if ($targetTypeName -notmatch 'Array' -or $p.Value.Count) - { - $p.Name + ' = ' + (stringify -value $p.Value -asArray $asArray -targetType $targetType ) + ";`n" - } + $p.Name + ' = ' + (stringify -value $p.Value -asArray $asArray -targetType $targetType ) + ";`n" } } } diff --git a/test/PSDesiredStateConfiguration.Tests.ps1 b/test/PSDesiredStateConfiguration.Tests.ps1 index b3edda9..9859a1d 100644 --- a/test/PSDesiredStateConfiguration.Tests.ps1 +++ b/test/PSDesiredStateConfiguration.Tests.ps1 @@ -439,4 +439,31 @@ MultiResourceConfig -OutputPath TestDrive:\MultiResourceConfig "TestDrive:\MultiResourceConfig\localhost.mof" | Should -Exist Get-Content -Raw -Path "TestDrive:\MultiResourceConfig\localhost.mof" | Write-Verbose -Verbose } + + It "Check empty array compilation" { + + [Scriptblock]::Create(@" +configuration DSCEmptyArrayConfig +{ + Import-DscResource -ModuleName xTestClassResource + Node "localhost" { + xTestClassResource f2 + { + Name = 'TestName' + Value = 'TestValue' + + sArray = @() + } + } +} + +DSCEmptyArrayConfig -OutputPath TestDrive:\DSCEmptyArrayConfig +"@) | Should -Not -Throw + + "TestDrive:\DSCEmptyArrayConfig\localhost.mof" | Should -Exist + + $mofContent = Get-Content -Raw -Path "TestDrive:\DSCEmptyArrayConfig\localhost.mof" + $mofContent | Write-Verbose -Verbose + $mofContent -match '\ssArray\s=\s{\r\n};' | Should -BeTrue + } }