From 307bcb8600b814d6f6d124a79097ddede718c779 Mon Sep 17 00:00:00 2001 From: Ben Wilkinson Date: Sun, 4 Apr 2021 20:44:47 -0700 Subject: [PATCH 1/2] 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 } } } From e1815742c42c1271a501002134df29001384908a Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Fri, 9 Apr 2021 11:46:13 +0200 Subject: [PATCH 2/2] ScheduledTask: Fixed execution account missing domain name (#356) * Fixed execution account missing domain name * Prevented an issue when the scheduled task is not yet created. * Update to changelog * Merge branch 'master' into fix-missing-domain-name * Reduced line length * Merge branch 'fix-missing-domain-name' of https://github.com/jensotto/ComputerManagementDsc into fix-missing-domain-name * Fixed a typo that was not supposed to be commited --- CHANGELOG.md | 3 ++- .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee2d68c..61d74daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed issue with disabling scheduled tasks that have "Run whether user is logged on or not" configured - Fixes [Issue #306](https://github.com/dsccommunity/ComputerManagementDsc/issues/306). - Fixed issue with `ExecuteAsCredential` not returning fully qualified username - on newer versions of Windows 10 and Windows Server 2019 - Fixes [Issue #352](https://github.com/dsccommunity/ComputerManagementDsc/issues/352). + on newer versions of Windows 10 and Windows Server 2019 for both local + accounts and domain accounts - Fixes [Issue #352](https://github.com/dsccommunity/ComputerManagementDsc/issues/352). - Fixed issue with `StartTime` failing Test-Resource if not specified in the resource - Fixes [Issue #148](https://github.com/dsccommunity/ComputerManagementDsc/issues/148). - PendingReboot diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 6d56125e..51abe5ab 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1448,9 +1448,18 @@ function Test-TargetResource To resolve this, add the computer name if it is missing and if it was passed in the ExecuteAsCredential parameter. #> - if ($username -cmatch '\\' -and $currentValues.ExecuteAsCredential -cnotmatch '\\') + if ($username -match "$ENV:COMPUTERNAME\\" -and $currentValues.ExecuteAsCredential) { - $currentValues.ExecuteAsCredential = "$ENV:COMPUTERNAME\$($currentValues.ExecuteAsCredential)" + $currentValues.ExecuteAsCredential = Set-DomainNameInAccountName ` + -AccountName $currentValues.ExecuteAsCredential ` + -DomainName $ENV:COMPUTERNAME + } + + if ($username -match "$ENV:USERDOMAIN\\" -and $currentValues.ExecuteAsCredential) + { + $currentValues.ExecuteAsCredential = Set-DomainNameInAccountName ` + -AccountName $currentValues.ExecuteAsCredential ` + -DomainName $ENV:USERDOMAIN } } else