Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Get-TargetResource

$getWindowsPackageParams = @{
PackageName = $Name
Online = $true
Online = [switch]::Present
}

if ($PSBoundParameters.ContainsKey('LogPath'))
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand All @@ -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' {
Expand Down