Skip to content

Commit 27e8e53

Browse files
authored
Moved the configurations WindowsFeatures and WindowsOptionalFeature to xPSDesiredStateConfiguration (#214)
* Moved resources to 'xPSDesiredStateConfiguration' * Disabled shallow fetch * WindowsFeatures no also uses the x resource with backward compatibility * Updated changelog
1 parent c65f5a7 commit 27e8e53

File tree

7 files changed

+58
-14
lines changed

7 files changed

+58
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- remove unused code after migration to HyperVDsc
3636
- Pipeline
3737
- Updated to latest Sampler files and update an vmImage reference to `ubuntu-latest`
38+
- `WindowsOptionalFeatures` and `WindowsFeatures` are using the DSC resource in `xPSDesiredStateConfiguration` now.
3839

3940
## [0.9.0] - 2023-02-08
4041

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ variables:
1616
buildArtifactName: output
1717
testResultFolderName: testResults
1818
defaultBranch: main
19+
Agent.Source.Git.ShallowFetchDepth: 0
1920

2021
stages:
2122
- stage: Build

doc/WindowsFeatures.adoc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
[[dscyml_windowsfeatures_abstract, {abstract}]]
1212
{abstract}
1313

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

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

2225

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

4750
| [[dscyml_windowsfeatures_features, {YmlCategory}/Features]]<<dscyml_windowsfeatures_features_details, Features>>
48-
|
51+
|
4952
| Hashtable[]
5053
| List windows features with additional properties
5154
|
@@ -108,6 +111,14 @@ To ensure that the role or feature is removed, set the property to `Absent`.
108111
| - *Present* (default)
109112
- Absent
110113

114+
| UseLegacyResource
115+
|
116+
| String
117+
| Indicates if the resource `WindowsFeature` should be used instead of the `xWindowsFeature` resource.
118+
119+
| - *false* (default)
120+
- true
121+
111122
|===
112123

113124

@@ -123,6 +134,7 @@ WindowsFeatures:
123134
Features:
124135
- Name: NET-Framework-Core
125136
Source: \\contoso.com\InstallationSources\WinSxs
137+
UseLegacyResource: true
126138
- Name: RSAT-AD-Tools
127139
IncludeAllSubFeature: true
128140
----

doc/WindowsOptionalFeatures.adoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
[#dscyml_windowsoptionalfeatures]
99
= DSC Resource '{YmlCategory}'
1010

11-
[[dscyml_windowsoptionalfeatures_abstract, {abstract}]]
11+
[[dscyml_windowsoptionalfeature_abstract, {abstract}]]
1212
{abstract}
1313

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

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

2225

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

3942
| RemoveFilesOnDisable

source/DSCResources/WindowsFeatures/WindowsFeatures.schema.psm1

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ configuration WindowsFeatures {
66

77
[Parameter()]
88
[hashtable[]]
9-
$Features
9+
$Features,
10+
11+
[Parameter()]
12+
[bool]$UseLegacyResource = $false
1013
)
1114

1215
Import-DscResource -ModuleName PSDesiredStateConfiguration
16+
Import-DscResource -ModuleName xPSDesiredStateConfiguration
17+
18+
$resourceName = if ($UseLegacyResource)
19+
{
20+
'WindowsFeature'
21+
}
22+
else
23+
{
24+
'xWindowsFeature'
25+
}
1326

1427
foreach ($n in $Names)
1528
{
@@ -35,7 +48,7 @@ configuration WindowsFeatures {
3548
IncludeAllSubFeature = $includeAllSubFeature
3649
}
3750

38-
(Get-DscSplattedResource -ResourceName WindowsFeature -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
51+
(Get-DscSplattedResource -ResourceName $resourceName -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
3952
}
4053

4154
<#
@@ -52,6 +65,16 @@ configuration WindowsFeatures {
5265
#>
5366
foreach ($feature in $Features)
5467
{
55-
(Get-DscSplattedResource -ResourceName WindowsFeature -ExecutionName $feature.Name -Properties $feature -NoInvoke).Invoke($feature)
68+
$resourceName = if ($feature.UseLegacyResource)
69+
{
70+
'WindowsFeature'
71+
}
72+
else
73+
{
74+
'xWindowsFeature'
75+
}
76+
$feature.remove('UseLegacyResource')
77+
78+
(Get-DscSplattedResource -ResourceName $resourceName -ExecutionName $feature.Name -Properties $feature -NoInvoke).Invoke($feature)
5679
}
5780
}

source/DSCResources/WindowsOptionalFeatures/WindowsOptionalFeatures.schema.psm1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ configuration WindowsOptionalFeatures {
1414
)
1515

1616
Import-DscResource -ModuleName PSDesiredStateConfiguration
17+
Import-DscResource -ModuleName xPSDesiredStateConfiguration
1718

1819
foreach ($n in $Names)
1920
{
20-
$ensure = 'Enable'
21+
$ensure = 'Present'
2122

2223
if ($n[0] -in '-', '+')
2324
{
2425
if ($n[0] -eq '-')
2526
{
26-
$ensure = 'Disable'
27+
$ensure = 'Absent'
2728
}
2829
$n = $n.Substring(1)
2930
}
@@ -35,6 +36,6 @@ configuration WindowsOptionalFeatures {
3536
NoWindowsUpdateCheck = $NoWindowsUpdateCheck
3637
}
3738

38-
(Get-DscSplattedResource -ResourceName WindowsOptionalFeature -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
39+
(Get-DscSplattedResource -ResourceName xWindowsOptionalFeature -ExecutionName $params.Name -Properties $params -NoInvoke).Invoke($params)
3940
}
4041
}

tests/Unit/DSCResources/Assets/Config/WindowsFeatures.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ Names:
66
Features:
77
- Name: NET-Framework-Core
88
Source: \\contoso.com\InstallationSources\WinSxs
9+
UseLegacyResource: true
10+
- Name: NET-Framework-Core
11+
UseLegacyResource: false
912
- Name: RSAT-AD-Tools
1013
IncludeAllSubFeature: true

0 commit comments

Comments
 (0)