Skip to content

Commit 3742e73

Browse files
Merge pull request #64 from PowerShell/dev
Merging release pull request
2 parents 7946497 + 926390d commit 3742e73

12 files changed

Lines changed: 1631 additions & 22 deletions

DSCResources/MSFT_xRegistryResource/MSFT_xRegistryResource.psm1

Lines changed: 1132 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[ClassVersion("1.0.0"), FriendlyName("xRegistry")]
2+
class MSFT_xRegistryResource : OMI_BaseResource
3+
{
4+
[Key] string Key;
5+
[Key] string ValueName;
6+
[Write] string ValueData[];
7+
[Write,ValueMap{"String", "Binary", "Dword", "Qword", "MultiString", "ExpandString"},Values{"String", "Binary", "Dword", "Qword", "MultiString", "ExpandString"}] string ValueType;
8+
[Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
9+
[Write] boolean Hex;
10+
[Write] boolean Force;
11+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma namespace("\\\\.\\root\\default")
2+
instance of __namespace{ name="MS_409";};
3+
#pragma namespace("\\\\.\\root\\default\\MS_409")
4+
5+
[Description("This resource is used to perform Get, Set and Test operations on Windows Registry.") : Amended,AMENDMENT, LOCALE(0x0409)]
6+
class MSFT_xRegistryResource : OMI_BaseResource
7+
{
8+
[Key,Description("Path of the registry key.\n") : Amended] string Key;
9+
[Key,Description("Name of the registry key value.\n") : Amended] string ValueName;
10+
[Description("Data of the registry key value.\n") : Amended] string ValueData[];
11+
[Description("Type of the registry key data.\n") : Amended] string ValueType;
12+
[Description("Enumerated value describing if the environment variable should exist on target machine.\nPresent {default} \nAbsent \n") : Amended] string Ensure;
13+
[Description("Flag to identify Hex or Decimal values.\n") : Amended] boolean Hex;
14+
[Description("Flag to specify forced execution.\n") : Amended] boolean Force;
15+
};
16+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Localized 10/30/2015 03:58 AM (GMT) 303:4.80.0411 MSFT_xRegistryResource.strings.psd1
2+
# Localized resources for MSFT_xRegistryResource
3+
4+
ConvertFrom-StringData @'
5+
###PSLOC
6+
ParameterValueInvalid=(ERROR) Parameter '{0}' has an invalid value '{1}' for type '{2}'
7+
InvalidPSDriveSpecified=(ERROR) Invalid PSDrive '{0}' specified in registry key '{1}'
8+
InvalidRegistryHiveSpecified=(ERROR) Invalid registry hive was specified in registry key '{0}'
9+
SetRegValueFailed=(ERROR) Failed to set registry key value '{0}' to value '{1}' of type '{2}'
10+
SetRegValueUnchanged=(UNCHANGED) No change to registry key value '{0}' containing '{1}'
11+
SetRegKeyUnchanged=(UNCHANGED) No change to registry key '{0}'
12+
SetRegValueSucceeded=(SET) Set registry key value '{0}' to '{1}' of type '{2}'
13+
SetRegKeySucceeded=(SET) Create registry key '{0}'
14+
SetRegKeyFailed=(ERROR) Failed to created registry key '{0}'
15+
RemoveRegKeyTreeFailed=(ERROR) Registry Key '{0}' has subkeys, cannot remove without Force flag
16+
RemoveRegKeySucceeded=(REMOVAL) Registry key '{0}' removed
17+
RemoveRegKeyFailed=(ERROR) Failed to remove registry key '{0}'
18+
RemoveRegValueSucceeded=(REMOVAL) Registry key value '{0}' removed
19+
RemoveRegValueFailed=(ERROR) Failed to remove registry key value '{0}'
20+
RegKeyDoesNotExist=Registry key '{0}' does not exist
21+
RegKeyExists=Registry key '{0}' exists
22+
RegValueExists=Found registry key value '{0}' with type '{1}' and data '{2}'
23+
RegValueDoesNotExist=Registry key value '{0}' does not exist
24+
RegValueTypeMismatch=Registry key value '{0}' of type '{1}' does not exist
25+
RegValueDataMismatch=Registry key value '{0}' of type '{1}' does not contain data '{2}'
26+
DefaultValueDisplayName=(Default)
27+
###PSLOC
28+
'@

DSCResources/MSFT_xRemoteFile/MSFT_xRemoteFile.schema.mof

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class MSFT_xRemoteFile : OMI_BaseResource
77
[Write, Description("User agent for the web request.")] String UserAgent;
88
[Write, EmbeddedInstance("MSFT_KeyValuePair"), Description("Headers of the web request.")] String Headers[];
99
[Write, EmbeddedInstance("MSFT_Credential"), Description("Specifies a user account that has permission to send the request.")] String Credential;
10-
[Write, Description("A boolean value to indicate whether the remote file should be re-downloaded if file in the DestinationPath was modified locally.")] Boolean MatchSource;
11-
[Read, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}, Description("Says whether DestinationPath exists on the machine")] String Ensure;
10+
[Write, Description("A boolean value to indicate whether the remote file should be re-downloaded if the file in the DestinationPath was modified locally.")] Boolean MatchSource;
11+
[Read, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}, Description("Says whether DestinationPath exists on the machine")] String Ensure;
1212
};
1313

1414

DSCResources/MSFT_xServiceResource/MSFT_xServiceResource.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,15 @@ function Set-TargetResource
282282
}
283283
if($PSBoundParameters.ContainsKey("Dependencies"))
284284
{
285-
$argumentsToNewService.Add("Dependencies", $Dependencies)
285+
$argumentsToNewService.Add("DependsOn", $Dependencies)
286286
}
287287
try
288288
{
289289
New-Service @argumentsToNewService
290290
}
291291
catch
292292
{
293-
Write-Log -Message ("Error creating service `"$($argumentsToNewService["Name"])`"", $_.Exception.Message)
293+
Write-Log -Message ("Error creating service `"$($argumentsToNewService["Name"])`"; Exception Message: $($_.Exception.Message)")
294294
throw $_
295295
}
296296

DSCResources/MSFT_xWindowsOptionalFeature/MSFT_xWindowsOptionalFeature.psm1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DATA localizedData
66
# culture = "en-US"
77
ConvertFrom-StringData @'
88
DismNotAvailable = PowerShell module Dism could not be imported.
9-
NotAClientSku = This Resource is only available for Windows Client.
9+
NotSupportedSku = This Resource is only available for Windows Client or Server 2012 (or later).
1010
ElevationRequired = This Resource requires to be run as an Administrator.
1111
ValidatingPrerequisites = Validating prerequisites...
1212
CouldNotCovertFeatureState = Could not convert feature state '{0}' into Absent/Present.
@@ -155,11 +155,11 @@ function Set-TargetResource
155155
{
156156
if ($NoWindowsUpdateCheck)
157157
{
158-
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -LimitAccess
158+
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -LimitAccess -NoRestart
159159
}
160160
else
161161
{
162-
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters
162+
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -NoRestart
163163
}
164164

165165
Write-Verbose ($LocalizedData.FeatureInstalled -f $Name)
@@ -168,11 +168,11 @@ function Set-TargetResource
168168
{
169169
if ($RemoveFilesOnDisable)
170170
{
171-
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -Remove
171+
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -Remove -NoRestart
172172
}
173173
else
174174
{
175-
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters
175+
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -NoRestart
176176
}
177177

178178
Write-Verbose ($LocalizedData.FeatureUninstalled -f $Name)
@@ -182,6 +182,7 @@ function Set-TargetResource
182182
throw ($LocalizedData.EnsureNotSupported -f $Ensure)
183183
}
184184

185+
## Indicate we need a restart as needed
185186
if ($feature.RestartNeeded)
186187
{
187188
Write-Verbose $LocalizedData.RestartNeeded
@@ -234,12 +235,11 @@ function Test-TargetResource
234235
{
235236
$result = $Ensure -eq 'Absent'
236237
}
237-
if (($result.State -eq 'Disabled' -and $Ensure -eq 'Absent')`
238-
-or ($result.State -eq 'Enabled' -and $Ensure -eq 'Present'))
238+
if (($featureState.State -eq 'Disabled' -and $Ensure -eq 'Absent')`
239+
-or ($featureState.State -eq 'Enabled' -and $Ensure -eq 'Present'))
239240
{
240241
$result = $true
241242
}
242-
243243
Write-Debug ($LocalizedData.TestTargetResourceEndMessage -f $Name)
244244
return $result
245245
}
@@ -250,12 +250,12 @@ function ValidatePrerequisites
250250
{
251251
Write-Verbose $LocalizedData.ValidatingPrerequisites
252252

253-
# check that we're running on a client SKU
254-
$os = Get-CimInstance -ClassName Win32_OperatingSystem
253+
# check that we're running on Server 2012 (or later) or on a client SKU
254+
$os = Get-CimInstance -ClassName Win32_OperatingSystem
255255

256-
if ($os.ProductType -ne 1)
256+
if (($os.ProductType -ne 1) -and ([System.Int32] $os.BuildNumber -lt 9600))
257257
{
258-
throw $LocalizedData.NotAClientSku
258+
throw $LocalizedData.NotSupportedSku
259259
}
260260

261261
# check that we are running elevated

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# xPSDesiredStateConfiguration
44

55
The **xPSDesiredStateConfiguration** module is a more recent, experimental version of the PSDesiredStateConfiguration module that ships in Windows as part of PowerShell 4.0.
6-
The module contains the **xDscWebService**, **xWindowsProcess**, **xService**, **xPackage**, **xRemoteFile**, and **xGroup** DSC resources, as well as the **xFileUpload** composite DSC resource.
6+
The module contains the **xDscWebService**, **xWindowsProcess**, **xService**, **xPackage**, **xRemoteFile**, **xWindowsOptionalFeature** and **xGroup** DSC resources, as well as the **xFileUpload** composite DSC resource.
77

88
## Contributing
99
Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md).
@@ -18,7 +18,9 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
1818
* **xRemoteFile** ensures the presence of remote files on a local machine.
1919
* **xPackage** manages the installation of .msi and .exe packages.
2020
* **xGroup** configures and manages local Windows groups
21-
* **xFileUpload** is a composite resource which ensures that local files exist on an SMB share.
21+
* **xFileUpload** is a composite resource which ensures that local files exist on an SMB share.
22+
* **xWindowsOptionalFeature** configures optional Windows features.
23+
* **xRegistry** is a copy of the built-in Registry resource, with some small bug fixes.
2224

2325
### xArchive
2426

@@ -131,11 +133,46 @@ Domain members may be specified using domain\name or Universal Principal Name (U
131133
* **Credential**: PSCredential for the user with access to DestinationPath.
132134
* **CertificateThumbprint**: Thumbprint of the certificate which should be used for encryption/decryption.
133135

136+
### xRegistry
137+
138+
This is a copy of the built-in Registry resource from the PSDesiredStateConfiguration module, with one small change: it now supports
139+
registry keys whose names contain forward slashes.
140+
141+
### xWindowsOptionalFeature
142+
Note: _the xWindowsOptionalFeature is only supported on Windows client or Windows Server 2012 (and later) SKUs._
143+
144+
* **Name**: Name of the optional Windows feature.
145+
* **Source**: Specifies the location of the files that are required to restore a feature that has been removed from the image.
146+
- You can specify the Windows directory of a mounted image or a running Windows installation that is shared on the network.
147+
- If you specify multiple Source arguments, the files are gathered from the first location where they are found and the rest of the locations are ignored.
148+
* **RemoveFilesOnDisable**: Removes the files for an optional feature without removing the feature's manifest from the image.
149+
- Suported values: $true, $false.
150+
- Default value: $false.
151+
* **LogPath**: Specifies the full path and file name to log to.
152+
- If not set, the default is %WINDIR%\Logs\Dism\dism.log.
153+
* **Ensure**: Ensures that the feature is present or absent.
154+
- Supported values: Present, Absent.
155+
- Default Value: Present.
156+
* **NoWindowsUpdateCheck**: Prevents DISM from contacting Windows Update (WU) when searching for the source files to restore a feature on an online image.
157+
- Suported values: $true, $false.
158+
- Default value: $false.
159+
* **LogLevel**: Specifies the maximum output level shown in the logs.
160+
- Suported values: ErrorsOnly, ErrorsAndWarning, ErrorsAndWarningAndInformation.
161+
- Default value: ErrorsOnly.
134162

135163
## Versions
136164

137165
### Unreleased
138166

167+
### 3.7.0.0
168+
169+
* xService:
170+
- Fixed a bug where 'Dependencies' property was not picked up and caused exception when set.
171+
* xWindowsOptionalFeature:
172+
- Fixed bug where Test-TargetResource method always failed.
173+
- Added support for Windows Server 2012 (and later) SKUs.
174+
* Added xRegistry resource
175+
139176
### 3.6.0.0
140177
* Added CreateCheckRegValue parameter to xPackage resource
141178
* Added MatchSource parameter to xRemoteFile resource
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
Get-Module MSFT_xRegistryResource | Remove-Module -Force
4+
Import-Module $PSScriptRoot\..\DSCResources\MSFT_xRegistryResource\MSFT_xRegistryResource.psm1 -Prefix UnitTest
5+
6+
Describe 'MSFT_xRegistryResource' {
7+
BeforeAll {
8+
$rootPath = 'Software\__MSFT_xRegistryResource__'
9+
$rootPathWithDrive = "HKCU:\$rootPath"
10+
if (Test-Path -LiteralPath $rootPathWithDrive)
11+
{
12+
Remove-Item -LiteralPath $rootPathWithDrive -Recurse -Force
13+
}
14+
15+
New-Item -Path $rootPathWithDrive
16+
}
17+
18+
AfterAll {
19+
if (Test-Path -LiteralPath $rootPathWithDrive)
20+
{
21+
Remove-Item -LiteralPath $rootPathWithDrive -Recurse -Force
22+
}
23+
}
24+
25+
It 'Supports keys containing forward slashes' {
26+
$keyName = 'Test/Key'
27+
$valueName = 'Testing'
28+
$valueData = 'TestValue'
29+
30+
$scriptBlock = {
31+
Set-UnitTestTargetResource -Key $rootPathWithDrive\$keyName `
32+
-ValueName $valueName `
33+
-ValueData $valueData `
34+
-ValueType String `
35+
-Force $true `
36+
-ErrorAction Stop
37+
}
38+
39+
$scriptBlock | Should Not Throw
40+
41+
$regKey = (Get-Item HKCU:\).OpenSubKey("$rootPath\$keyName")
42+
43+
$regKey | Should Not Be Null
44+
$regKey.GetValue($valueName) | Should Be $valueData
45+
}
46+
}
47+

0 commit comments

Comments
 (0)