Skip to content

Commit

Permalink
Moved the configurations WindowsFeatures and `WindowsOptionalFeatur…
Browse files Browse the repository at this point in the history
…e` to `xPSDesiredStateConfiguration` (#214)

* Moved resources to 'xPSDesiredStateConfiguration'

* Disabled shallow fetch

* WindowsFeatures no also uses the x resource with backward compatibility

* Updated changelog
  • Loading branch information
raandree authored May 23, 2023
1 parent c65f5a7 commit 27e8e53
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- remove unused code after migration to HyperVDsc
- Pipeline
- Updated to latest Sampler files and update an vmImage reference to `ubuntu-latest`
- `WindowsOptionalFeatures` and `WindowsFeatures` are using the DSC resource in `xPSDesiredStateConfiguration` now.

## [0.9.0] - 2023-02-08

Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ variables:
buildArtifactName: output
testResultFolderName: testResults
defaultBranch: main
Agent.Source.Git.ShallowFetchDepth: 0

stages:
- stage: Build
Expand Down
20 changes: 16 additions & 4 deletions doc/WindowsFeatures.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
[[dscyml_windowsfeatures_abstract, {abstract}]]
{abstract}

// reference links as variables for using more than once
:ref_xpsdesiredstateconfiguration_xwindowsfeature: https://github.com/dsccommunity/xPSDesiredStateConfiguration#xwindowsfeature[xwindowsfeature]


[cols="1,3a" options="autowidth" caption=]
|===
| Source | https://github.com/dsccommunity/CommonTasks/tree/main/source/DSCResources/WindowsFeatures
| DSC Resource | https://docs.microsoft.com/en-us/powershell/module/psdesiredstateconfiguration[PSDesiredStateConfiguration]
| Documentation | https://docs.microsoft.com/de-de/powershell/scripting/dsc/reference/resources/windows/windowsfeatureresource[WindowsFeature]
| Source | https://github.com/dsccommunity/CommonTasks/tree/main/source/DSCResources/WindowsOptionalFeatures
| DSC Resource | https://github.com/dsccommunity/xPSDesiredStateConfiguration[xPSDesiredStateConfiguration]
| Documentation | {ref_xpsdesiredstateconfiguration_xwindowsfeature}
|===


Expand Down Expand Up @@ -45,7 +48,7 @@ This is the same as the Name property from the `Get-WindowsFeature` cmdlet, and
| [+ \| -]<name>

| [[dscyml_windowsfeatures_features, {YmlCategory}/Features]]<<dscyml_windowsfeatures_features_details, Features>>
|
|
| Hashtable[]
| List windows features with additional properties
|
Expand Down Expand Up @@ -108,6 +111,14 @@ To ensure that the role or feature is removed, set the property to `Absent`.
| - *Present* (default)
- Absent

| UseLegacyResource
|
| String
| Indicates if the resource `WindowsFeature` should be used instead of the `xWindowsFeature` resource.

| - *false* (default)
- true

|===


Expand All @@ -123,6 +134,7 @@ WindowsFeatures:
Features:
- Name: NET-Framework-Core
Source: \\contoso.com\InstallationSources\WinSxs
UseLegacyResource: true
- Name: RSAT-AD-Tools
IncludeAllSubFeature: true
----
Expand Down
11 changes: 7 additions & 4 deletions doc/WindowsOptionalFeatures.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
[#dscyml_windowsoptionalfeatures]
= DSC Resource '{YmlCategory}'

[[dscyml_windowsoptionalfeatures_abstract, {abstract}]]
[[dscyml_windowsoptionalfeature_abstract, {abstract}]]
{abstract}

// reference links as variables for using more than once
:ref_xpsdesiredstateconfiguration_xwindowsoptionalfeature: https://github.com/dsccommunity/xPSDesiredStateConfiguration#xWindowsOptionalFeature[xWindowsOptionalFeature]


[cols="1,3a" options="autowidth" caption=]
|===
| Source | https://github.com/dsccommunity/CommonTasks/tree/main/source/DSCResources/WindowsOptionalFeatures
| DSC Resource | https://docs.microsoft.com/en-us/powershell/module/psdesiredstateconfiguration[PSDesiredStateConfiguration]
| Documentation | https://docs.microsoft.com/de-de/powershell/scripting/dsc/reference/resources/windows/windowsoptionalfeatureresource[WindowsOptionalFeature]
| DSC Resource | https://github.com/dsccommunity/xPSDesiredStateConfiguration[xPSDesiredStateConfiguration]
| Documentation | {ref_xpsdesiredstateconfiguration_xwindowsoptionalfeature}
|===


Expand All @@ -33,7 +36,7 @@
| Mandatory
| string
| Indicates the name of the feature that you want to ensure is added or removed.
This is the same as the Name property from the Get-WindowsOptionalFeature cmdlet, and not the display name of the feature.
This is the same as the Name property from the `Get-WindowsOptionalFeature` cmdlet, and not the display name of the feature.
| [+ \| -]<name>

| RemoveFilesOnDisable
Expand Down
29 changes: 26 additions & 3 deletions source/DSCResources/WindowsFeatures/WindowsFeatures.schema.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ configuration WindowsFeatures {

[Parameter()]
[hashtable[]]
$Features
$Features,

[Parameter()]
[bool]$UseLegacyResource = $false
)

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xPSDesiredStateConfiguration

$resourceName = if ($UseLegacyResource)
{
'WindowsFeature'
}
else
{
'xWindowsFeature'
}

foreach ($n in $Names)
{
Expand All @@ -35,7 +48,7 @@ configuration WindowsFeatures {
IncludeAllSubFeature = $includeAllSubFeature
}

(Get-DscSplattedResource -ResourceName WindowsFeature -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
(Get-DscSplattedResource -ResourceName $resourceName -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
}

<#
Expand All @@ -52,6 +65,16 @@ configuration WindowsFeatures {
#>
foreach ($feature in $Features)
{
(Get-DscSplattedResource -ResourceName WindowsFeature -ExecutionName $feature.Name -Properties $feature -NoInvoke).Invoke($feature)
$resourceName = if ($feature.UseLegacyResource)
{
'WindowsFeature'
}
else
{
'xWindowsFeature'
}
$feature.remove('UseLegacyResource')

(Get-DscSplattedResource -ResourceName $resourceName -ExecutionName $feature.Name -Properties $feature -NoInvoke).Invoke($feature)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ configuration WindowsOptionalFeatures {
)

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xPSDesiredStateConfiguration

foreach ($n in $Names)
{
$ensure = 'Enable'
$ensure = 'Present'

if ($n[0] -in '-', '+')
{
if ($n[0] -eq '-')
{
$ensure = 'Disable'
$ensure = 'Absent'
}
$n = $n.Substring(1)
}
Expand All @@ -35,6 +36,6 @@ configuration WindowsOptionalFeatures {
NoWindowsUpdateCheck = $NoWindowsUpdateCheck
}

(Get-DscSplattedResource -ResourceName WindowsOptionalFeature -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
(Get-DscSplattedResource -ResourceName xWindowsOptionalFeature -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
}
}
3 changes: 3 additions & 0 deletions tests/Unit/DSCResources/Assets/Config/WindowsFeatures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ Names:
Features:
- Name: NET-Framework-Core
Source: \\contoso.com\InstallationSources\WinSxs
UseLegacyResource: true
- Name: NET-Framework-Core
UseLegacyResource: false
- Name: RSAT-AD-Tools
IncludeAllSubFeature: true

0 comments on commit 27e8e53

Please sign in to comment.