diff --git a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 index a4e49c7..6be455b 100644 --- a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 +++ b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 @@ -62,7 +62,7 @@ function Get-TargetResource $getWindowsPackageParams = @{ PackageName = $Name - Online = $true + Online = [switch]::Present } if ($PSBoundParameters.ContainsKey('LogPath')) @@ -141,16 +141,26 @@ function Set-TargetResource { New-InvalidArgumentException -ArgumentName 'SourcePath' -Message ($script:localizedData.SourcePathDoesNotExist -f $SourcePath) } - + + $setTargetResourceParams = @{ + PackagePath = $SourcePath + Online = [switch]::Present + } + + if ($PSBoundParameters.ContainsKey('LogPath')) + { + $setTargetResourceParams['LogPath'] = $LogPath + } + if ($Ensure -ieq 'Present') { Write-Verbose -Message ($script:localizedData.AddingPackage -f $SourcePath) - Dism\Add-WindowsPackage -PackagePath $SourcePath -LogPath $LogPath -Online + Dism\Add-WindowsPackage @setTargetResourceParams } else { Write-Verbose -Message ($script:localizedData.RemovingPackage -f $SourcePath) - Dism\Remove-WindowsPackage -PackagePath $SourcePath -LogPath $LogPath -Online + Dism\Remove-WindowsPackage @setTargetResourceParams } Write-Verbose -Message ($script:localizedData.SetTargetResourceFinished -f $Name) diff --git a/README.md b/README.md index 807a2cb..f05e2ea 100644 --- a/README.md +++ b/README.md @@ -577,6 +577,9 @@ The following parameters will be the same for each process in the set: ### Unreleased +* WindowsPackageCab + * Changed LogPath parameter to be optional (issue [#109](https://github.com/PowerShell/PSDscResources/issues/109)). + ### 2.10.0.0 * Fixed CompanyName typo - Fixes [Issue #100](https://github.com/PowerShell/PSDscResources/issues/100) diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 9e899f9..33bac99 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -70,6 +70,11 @@ try $null = Get-TargetResource -Name $script:testPackageName -LogPath $script:testLogPath @getTargetResourceCommonParams Assert-MockCalled -CommandName 'Dism\Get-WindowsPackage' -ParameterFilter { $LogPath -eq $script:testLogPath } } + + It 'Should return an empty log path when it was not specified' { + $getTargetResourceResult = Get-TargetResource -Name $script:testPackageName @getTargetResourceCommonParams + $getTargetResourceResult.LogPath | Should be '' + } } Context 'Set-TargetResource' { @@ -84,12 +89,12 @@ try It 'Should call Add-WindowsPackage when Ensure is Present' { Set-TargetResource -Name $script:testPackageName -SourcePath $script:testSourcePath -Ensure 'Present' - Assert-MockCalled -CommandName 'Dism\Add-WindowsPackage' + Assert-MockCalled -CommandName 'Dism\Add-WindowsPackage' -ParameterFilter { $null -eq $LogPath } } It 'Should call Remove-WindowsPackage when Ensure is Absent' { Set-TargetResource -Name $script:testPackageName -SourcePath $script:testSourcePath -Ensure 'Absent' - Assert-MockCalled -CommandName 'Dism\Remove-WindowsPackage' + Assert-MockCalled -CommandName 'Dism\Remove-WindowsPackage' -ParameterFilter { $null -eq $LogPath } } It 'Should pass specified log path to Add-WindowsPackage' {