Skip to content

Commit

Permalink
WindowsCapability: Add 'Source' parameter when adding capability - Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brwilkinson authored Apr 5, 2021
1 parent 563d4aa commit 307bcb8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ The format is based on and uses the types of changes according to [Keep a Change
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- WindowsCapability
- Added the 'Source' parameter for Add-WindowsCapability as an
optional parameter - Fixes [Issue #361](https://github.com/dsccommunity/ComputerManagementDsc/issues/361)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ function Get-TargetResource
Specifies the full path and file name to log to. This is a write
only parameter that is used when updating the status of a Windows
Capability. If not specified, the default is '%WINDIR%\Logs\Dism\dism.log'.
.PARAMETER Source
Specifies the location of the files that are required to add a Windows
capability package to an image. You can specify the Windows directory
of a mounted image or a running Windows installation that is shared on the network.
#>
function Set-TargetResource
{
Expand All @@ -104,7 +109,11 @@ function Set-TargetResource

[Parameter()]
[System.String]
$LogPath
$LogPath,

[Parameter()]
[System.String]
$Source
)

Write-Verbose -Message ($script:localizedData.SetTargetResourceStartMessage -f $Name)
Expand All @@ -127,6 +136,12 @@ function Set-TargetResource
if ($Ensure -ne $currentState.Ensure)
{
Write-Verbose -Message ($script:localizedData.SetTargetRemoveMessage -f $Name)

if ($PSBoundParameters.ContainsKey('Source'))
{
$PSBoundParameters.Remove('Source')
}

$null = Remove-WindowsCapability -Online @PSBoundParameters
}
}
Expand Down Expand Up @@ -184,7 +199,11 @@ function Test-TargetResource

[Parameter()]
[System.String]
$LogPath
$LogPath,

[Parameter()]
[System.String]
$Source
)

$inDesiredState = $true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class DSC_WindowsCapability : OMI_BaseResource
[Write, Description("Specifies whether the Windows Capability should be installed or uninstalled. To install the Windows Capability, set this property to Present. To uninstall the Windows Capability, set the property to Absent."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure;
[Write, Description("Specifies the given Log Level of a Windows Capability. This is a write only parameter that is used when updating the status of a Windows Capability. If not specified, the default is 'WarningsInfo'."), ValueMap{"Errors", "Warnings", "WarningsInfo"}, Values{"Errors", "Warnings", "WarningsInfo"}] String LogLevel;
[Write, Description("Specifies the full path and file name to log to. This is a write only parameter that is used when updating the status of a Windows Capability. If not specified, the default is '%WINDIR%\\Logs\\Dism\\dism.log'.")] String LogPath;
[Write, Description("Specifies the location of the files that are required to add a Windows capability package to an image. You can specify the Windows directory of a mounted image or a running Windows installation that is shared on the network.")] String Source;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<#PSScriptInfo
.VERSION 1.0.0
.GUID 369d465e-244c-4789-90a6-6f3387e4c85a
.AUTHOR DSC Community
.COMPANYNAME DSC Community
.COPYRIGHT Copyright the DSC Community contributors. All rights reserved.
.TAGS DSCConfiguration
.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE
.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES First version.
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core
#>

#Requires -module ComputerManagementDsc

<#
.DESCRIPTION
Example script that adds the Windows Capability OpenSSH.Client~~~~0.0.1.0
and set the LogLevel to log Errors only and write the Logfile to Path C:\Temp.
This also uses the Source path for the installation.
#>
Configuration WindowsCapability_AddWindowsCapabilitywithLogLevelLogPathandSource_Config
{
Import-DSCResource -ModuleName ComputerManagementDsc

Node localhost
{
WindowsCapability OpenSSHClient
{
Name = 'OpenSSH.Client~~~~0.0.1.0'
Ensure = 'Present'
LogLevel = 'Errors'
LogPath = 'C:\Temp\Logfile.log'
Source = 'F:\Source\FOD\LanguagesAndOptionalFeatures'
}
}
}
1 change: 1 addition & 0 deletions tests/Integration/DSC_WindowsCapability.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Configuration DSC_WindowsCapability_Config
LogLevel = $Node.LogLevel
LogPath = $Node.LogPath
Ensure = $Node.Ensure
Source = $Node.Source
}
}
}

0 comments on commit 307bcb8

Please sign in to comment.