From 98c3691f1b82c97970e9bdc111978f62bb61945a Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 16:26:27 +0200 Subject: [PATCH 1/6] Pin Pester to 6.0.0-rc1 for v6 release-candidate pilot Change RequiredModules.psd1 from the floating Pester latest pin to the 6.0.0-rc1 prerelease pin. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- RequiredModules.psd1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 7c9328ee2..09e574aa5 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -9,7 +9,10 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' - Pester = 'latest' + Pester = @{ + Version = '6.0.0-rc1' + Parameters = @{ AllowPrerelease = $true } + } Plaster = 'latest' ModuleBuilder = 'latest' ChangelogManagement = 'latest' From 0fce0fed98ba16a9c23ad38fb1994df9344ceb60 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 18:47:52 +0200 Subject: [PATCH 2/6] Migrate unit tests for Pester v6 mock changes Pester v6 no longer falls through to the real command when a mock has only -ParameterFilter behaviours and none of them match - it throws instead. Restore the v5 behaviour the tests relied on by forwarding unmatched Test-Path calls to the real cmdlet, and suppress unmatched Write-Verbose calls (scoping the related Should -Invoke assertion to the asserted message so the count stays correct). Also replace the removed Assert-VerifiableMock with Should -InvokeVerifiable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ .../ActiveDirectoryDsc.Common.Tests.ps1 | 10 +++++----- tests/Unit/MSFT_ADDomain.Tests.ps1 | 9 +++++++++ tests/Unit/MSFT_WaitForADDomain.Tests.ps1 | 7 ++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0914461a7..2624755a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) ## [Unreleased] +### Changed + +- `ActiveDirectoryDsc` + - Updated unit tests for Pester 6 compatibility - forward unmatched `Test-Path` + mock calls to the real cmdlet, suppress unmatched `Write-Verbose` calls, and + replace the removed `Assert-VerifiableMock` with `Should -InvokeVerifiable`. + ## [6.7.1] - 2025-12-05 ### Added diff --git a/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 b/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 index 145f850e5..1308076a7 100644 --- a/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 +++ b/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 @@ -756,7 +756,7 @@ Describe 'ActiveDirectoryDsc.Common\Restore-ADCommonObject' { } It 'Should call Get-ADObject as well as Restore-ADObject' { - Assert-VerifiableMock + Should -InvokeVerifiable } It 'Should throw an InvalidOperationException when object parent does not exist' { @@ -1558,7 +1558,7 @@ Describe 'ActiveDirectoryDsc.Common\Get-ADDirectoryContext' { } } - Assert-VerifiableMock + Should -InvokeVerifiable } } @@ -1625,7 +1625,7 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr } } - Assert-VerifiableMock + Should -InvokeVerifiable } Context 'When no domain controller is found' { @@ -1661,7 +1661,7 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr Should -Invoke -CommandName Write-Verbose -Exactly -Times 1 -Scope It } - Assert-VerifiableMock + Should -InvokeVerifiable } Context 'When the lookup for a domain controller fails' { @@ -1686,7 +1686,7 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr Should -Invoke -CommandName Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It } - Assert-VerifiableMock + Should -InvokeVerifiable } Context 'When the Find-DomainController throws an authentication exception' { diff --git a/tests/Unit/MSFT_ADDomain.Tests.ps1 b/tests/Unit/MSFT_ADDomain.Tests.ps1 index 7cc12455c..eab2b89df 100644 --- a/tests/Unit/MSFT_ADDomain.Tests.ps1 +++ b/tests/Unit/MSFT_ADDomain.Tests.ps1 @@ -62,6 +62,9 @@ AfterAll { Describe 'MSFT_ADDomain\Get-TargetResource' -Tag 'Get' { BeforeAll { Mock -CommandName Assert-Module + # Pester v6 throws instead of calling the real command when no -ParameterFilter + # matches. Forward unmatched Test-Path calls to the real cmdlet to keep v5 behaviour. + Mock -CommandName Test-Path -MockWith { & (Get-Command -Name 'Test-Path' -CommandType Cmdlet) @PesterBoundParameters } Mock -CommandName Test-Path -ParameterFilter { $Path -eq 'C:\Windows\SysVol\contoso.com' } -MockWith { $true } @@ -675,6 +678,9 @@ Describe 'MSFT_ADDomain\Set-TargetResource' -Tag 'Set' { Context 'When the domain controller is pending reboot and SuppressReboot is $false' { BeforeAll { # Make the resource think a reboot is pending after installation. + # Pester v6 throws instead of calling the real command when no -ParameterFilter + # matches. Forward unmatched Test-Path calls to the real cmdlet to keep v5 behaviour. + Mock -CommandName Test-Path -MockWith { & (Get-Command -Name 'Test-Path' -CommandType Cmdlet) @PesterBoundParameters } Mock -CommandName Test-Path -ParameterFilter { $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\LocatorDCPromoPreRebootHint' } -MockWith { $true } @@ -1078,6 +1084,9 @@ Describe 'MSFT_ADDomain\Set-TargetResource' -Tag 'Set' { Context 'When the domain controller is pending reboot and SuppressReboot is $false' { BeforeAll { + # Pester v6 throws instead of calling the real command when no -ParameterFilter + # matches. Forward unmatched Test-Path calls to the real cmdlet to keep v5 behaviour. + Mock -CommandName Test-Path -MockWith { & (Get-Command -Name 'Test-Path' -CommandType Cmdlet) @PesterBoundParameters } Mock -CommandName Test-Path -ParameterFilter { $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\LocatorDCPromoPreRebootHint' } -MockWith { $true } diff --git a/tests/Unit/MSFT_WaitForADDomain.Tests.ps1 b/tests/Unit/MSFT_WaitForADDomain.Tests.ps1 index 035fc4fb8..2f8feecbd 100644 --- a/tests/Unit/MSFT_WaitForADDomain.Tests.ps1 +++ b/tests/Unit/MSFT_WaitForADDomain.Tests.ps1 @@ -157,6 +157,9 @@ Describe 'MSFT_WaitForADDomain\Get-TargetResource' -Tag 'Get' { Context 'When using BuiltInCredential parameter' { BeforeAll { + # Pester v6 throws instead of calling the real command when no -ParameterFilter + # matches. Suppress unmatched Write-Verbose calls (v5 let them through). + Mock -CommandName Write-Verbose -MockWith { } Mock -CommandName Write-Verbose -ParameterFilter { $Message -like 'Impersonating the credentials ''BuiltInCredential''*' } -MockWith { @@ -185,7 +188,9 @@ Describe 'MSFT_WaitForADDomain\Get-TargetResource' -Tag 'Get' { $result.Credential | Should -BeNullOrEmpty } - Should -Invoke -CommandName Write-Verbose -Exactly -Times 1 -Scope It + Should -Invoke -CommandName Write-Verbose -ParameterFilter { + $Message -like 'Impersonating the credentials ''BuiltInCredential''*' + } -Exactly -Times 1 -Scope It } } } From c34d1dac219d0e48dacc36c3aa1cdb382c3273db Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 20:03:27 +0200 Subject: [PATCH 3/6] Bump pilot to Pester 6.0.0-rc2 Re-run the release-candidate pilot against Pester 6.0.0-rc2, which includes the revert of the Should -HaveCount dictionary-counting change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- RequiredModules.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 09e574aa5..7e747a21c 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -10,7 +10,7 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' Pester = @{ - Version = '6.0.0-rc1' + Version = '6.0.0-rc2' Parameters = @{ AllowPrerelease = $true } } Plaster = 'latest' From 46742990190a5c555f09c02de75f04f00fb8abc1 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 21:18:10 +0200 Subject: [PATCH 4/6] Suppress unmatched Write-Verbose in Find-DomainController test for Pester 6 In the 'When no domain controller is found' context, Pester 6 throws instead of falling through to the real command when a mock has only -ParameterFilter behaviours and none match. Add a default Write-Verbose mock to swallow the unmatched verbose call and scope the related Should -Invoke assertion to the asserted message so the count stays at 1. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ActiveDirectoryDsc.Common.Tests.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 b/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 index 1308076a7..84082d8d5 100644 --- a/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 +++ b/tests/Unit/ActiveDirectoryDsc.Common/ActiveDirectoryDsc.Common.Tests.ps1 @@ -1647,6 +1647,9 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr ) } + # Pester v6 throws instead of calling the real command when no -ParameterFilter + # matches. Suppress unmatched Write-Verbose calls (v5 let them through). + Mock -CommandName Write-Verbose -MockWith { } Mock -CommandName Write-Verbose -ParameterFilter { $Message -like 'Searching for a domain controller*' } -MockWith { @@ -1658,7 +1661,9 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr { Find-DomainController -DomainName $mockDomainName } | Should -Not -Throw Should -Invoke -CommandName Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Write-Verbose -Exactly -Times 1 -Scope It + Should -Invoke -CommandName Write-Verbose -ParameterFilter { + $Message -like 'Searching for a domain controller*' + } -Exactly -Times 1 -Scope It } Should -InvokeVerifiable From b250f49d4a4e6d0a1bfafdd0a014175c74076324 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 1 Jul 2026 09:33:23 +0200 Subject: [PATCH 5/6] Bump Pester to 6.0.0-rc4 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- RequiredModules.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 7e747a21c..02769c971 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -10,7 +10,7 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' Pester = @{ - Version = '6.0.0-rc2' + Version = '6.0.0-rc4' Parameters = @{ AllowPrerelease = $true } } Plaster = 'latest' From eeff38ae52e0a77ca929e6d43996bd2dabd6072d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 7 Jul 2026 10:35:13 +0200 Subject: [PATCH 6/6] Update Pester pin to the released 6.0.0 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- RequiredModules.psd1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 02769c971..10e4d97c9 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -10,8 +10,7 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' Pester = @{ - Version = '6.0.0-rc4' - Parameters = @{ AllowPrerelease = $true } + Version = '6.0.0' } Plaster = 'latest' ModuleBuilder = 'latest'