diff --git a/DSCResources/MSFT_xADComputer/MSFT_xADComputer.psm1 b/DSCResources/MSFT_xADComputer/MSFT_xADComputer.psm1 index 7852c584e..14bd5891b 100644 --- a/DSCResources/MSFT_xADComputer/MSFT_xADComputer.psm1 +++ b/DSCResources/MSFT_xADComputer/MSFT_xADComputer.psm1 @@ -953,30 +953,6 @@ function Set-TargetResource } } -<# - .SYNOPSIS - This is a wrapper for Set-ADComputer. - - .PARAMETER Parameters - A hash table containing all parameters that will be passed trough to - Set-ADComputer. - - .NOTES - This is needed because of how Pester is unable to handle mocking the - cmdlet Set-ADComputer. -#> -function Set-DscADComputer -{ - param - ( - [Parameter(Mandatory = $true)] - [System.Collections.Hashtable] - $Parameters - ) - - Set-ADComputer @Parameters | Out-Null -} - <# .SYNOPSIS This evaluates the service principal names current state against the diff --git a/DSCResources/MSFT_xADObjectEnabledState/MSFT_xADObjectEnabledState.psm1 b/DSCResources/MSFT_xADObjectEnabledState/MSFT_xADObjectEnabledState.psm1 index 304790717..104df9450 100644 --- a/DSCResources/MSFT_xADObjectEnabledState/MSFT_xADObjectEnabledState.psm1 +++ b/DSCResources/MSFT_xADObjectEnabledState/MSFT_xADObjectEnabledState.psm1 @@ -352,27 +352,3 @@ function Set-TargetResource } } } - -<# - .SYNOPSIS - This is a wrapper for Set-ADComputer. - - .PARAMETER Parameters - A hash table containing all parameters that will be passed trough to - Set-ADComputer. - - .NOTES - This is needed because of how Pester is unable to handle mocking the - cmdlet Set-ADComputer. -#> -function Set-DscADComputer -{ - param - ( - [Parameter(Mandatory = $true)] - [System.Collections.Hashtable] - $Parameters - ) - - Set-ADComputer @Parameters | Out-Null -} diff --git a/Modules/xActiveDirectory.Common/xActiveDirectory.Common.psm1 b/Modules/xActiveDirectory.Common/xActiveDirectory.Common.psm1 index e18dec420..32d5f90dd 100644 --- a/Modules/xActiveDirectory.Common/xActiveDirectory.Common.psm1 +++ b/Modules/xActiveDirectory.Common/xActiveDirectory.Common.psm1 @@ -468,6 +468,31 @@ function Start-ProcessWithTimeout return $sqlSetupProcess.ExitCode } +<# + .SYNOPSIS + This is a wrapper for Set-ADComputer. + + .PARAMETER Parameters + A hash table containing all parameters that will be passed trough to + Set-ADComputer. + + .NOTES + This is needed because of how Pester is unable to handle mocking the + cmdlet Set-ADComputer. +#> +function Set-DscADComputer +{ + param + ( + [Parameter(Mandatory = $true)] + [System.Collections.Hashtable] + $Parameters + ) + + Set-ADComputer @Parameters | Out-Null +} + +# This row should be last in the module, just before the cmdlet Export-ModuleMember. $script:localizedData = Get-LocalizedData -ResourceName 'xActiveDirectory.Common' -ScriptRoot $PSScriptRoot Export-ModuleMember -Function @( @@ -478,4 +503,5 @@ Export-ModuleMember -Function @( 'Get-LocalizedData' 'Test-DscParameterState' 'Start-ProcessWithTimeout' + 'Set-DscADComputer' ) diff --git a/Tests/Unit/xActiveDirectory.Common.Tests.ps1 b/Tests/Unit/xActiveDirectory.Common.Tests.ps1 index b6ae6f135..062d4439f 100644 --- a/Tests/Unit/xActiveDirectory.Common.Tests.ps1 +++ b/Tests/Unit/xActiveDirectory.Common.Tests.ps1 @@ -512,5 +512,42 @@ InModuleScope 'xActiveDirectory.Common' { } } } + + Describe 'DscResource.Common\Set-DscADComputer' { + Context 'When calling with a hashtable' { + BeforeAll { + <# + Pester is unable to mock the real cmdlet Set-ADComputer, + so this a dummy function to be able to mock the cmdlet + Set-ADComputer. + #> + function Set-ADComputer + { + param + ( + [Parameter()] + [System.Collections.Hashtable] + $Replace + ) + } + + Mock -CommandName Set-ADComputer + } + + It 'Should call Set-ADComputer with the correct parameter' { + { + Set-DscADComputer -Parameters @{ + Replace = @{ + Location = 'New location' + } + } + } | Should -Not -Throw + + Assert-MockCalled -CommandName Set-ADComputer -ParameterFilter { + $Replace.ContainsKey('Location') -eq $true + } -Exactly -Times 1 -Scope It + } + } + } }