From 6a884823c9cab1d4a1db39fcf7f5100fd1895f07 Mon Sep 17 00:00:00 2001 From: DoLearnWhileAlive <64268800+DoLearnWhileAlive@users.noreply.github.com> Date: Thu, 24 Apr 2025 15:14:48 +0200 Subject: [PATCH 1/2] ConvertTo-MOFInstance: Include resource properties with empty array value --- .../PSDesiredStateConfiguration.psm1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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" } } } From 54c0d57469dce9815f04373228a11fac9e5d7e84 Mon Sep 17 00:00:00 2001 From: Fabian Obst Date: Mon, 29 Sep 2025 11:26:14 +0200 Subject: [PATCH 2/2] Add test for checking mof compilation with empty array value --- test/PSDesiredStateConfiguration.Tests.ps1 | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 + } }