From 307bcb8600b814d6f6d124a79097ddede718c779 Mon Sep 17 00:00:00 2001 From: Ben Wilkinson Date: Sun, 4 Apr 2021 20:44:47 -0700 Subject: [PATCH] WindowsCapability: Add 'Source' parameter when adding capability - Fixes #361 --- CHANGELOG.md | 3 ++ .../DSC_WindowsCapability.psm1 | 23 ++++++++++- .../DSC_WindowsCapability.schema.mof | 1 + ...itywithLogLevelLogPathandSource_Config.ps1 | 41 +++++++++++++++++++ .../DSC_WindowsCapability.config.ps1 | 1 + 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 source/Examples/Resources/WindowsCapability/4-WindowsCapability_AddWindowsCapabilitywithLogLevelLogPathandSource_Config.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8108e07c..8ee2d68c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.psm1 b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.psm1 index 64f8f485..d5eeba8e 100644 --- a/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.psm1 +++ b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.psm1 @@ -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 { @@ -104,7 +109,11 @@ function Set-TargetResource [Parameter()] [System.String] - $LogPath + $LogPath, + + [Parameter()] + [System.String] + $Source ) Write-Verbose -Message ($script:localizedData.SetTargetResourceStartMessage -f $Name) @@ -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 } } @@ -184,7 +199,11 @@ function Test-TargetResource [Parameter()] [System.String] - $LogPath + $LogPath, + + [Parameter()] + [System.String] + $Source ) $inDesiredState = $true diff --git a/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.schema.mof b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.schema.mof index 339247a5..89be94ee 100644 --- a/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.schema.mof +++ b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.schema.mof @@ -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; }; diff --git a/source/Examples/Resources/WindowsCapability/4-WindowsCapability_AddWindowsCapabilitywithLogLevelLogPathandSource_Config.ps1 b/source/Examples/Resources/WindowsCapability/4-WindowsCapability_AddWindowsCapabilitywithLogLevelLogPathandSource_Config.ps1 new file mode 100644 index 00000000..4d35217a --- /dev/null +++ b/source/Examples/Resources/WindowsCapability/4-WindowsCapability_AddWindowsCapabilitywithLogLevelLogPathandSource_Config.ps1 @@ -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' + } + } +} diff --git a/tests/Integration/DSC_WindowsCapability.config.ps1 b/tests/Integration/DSC_WindowsCapability.config.ps1 index 1083ef78..f2de301d 100644 --- a/tests/Integration/DSC_WindowsCapability.config.ps1 +++ b/tests/Integration/DSC_WindowsCapability.config.ps1 @@ -11,6 +11,7 @@ Configuration DSC_WindowsCapability_Config LogLevel = $Node.LogLevel LogPath = $Node.LogPath Ensure = $Node.Ensure + Source = $Node.Source } } }