Skip to content

Commit

Permalink
Merge pull request #226 from kwirkykat/MergeRegistry
Browse files Browse the repository at this point in the history
xRegistry: Merge with In-Box Resource, Add Tests, and Fix Key/Value Removal
  • Loading branch information
kwirkykat authored Sep 12, 2016
2 parents 10df41c + bbbc0b4 commit e907b85
Show file tree
Hide file tree
Showing 7 changed files with 852 additions and 77 deletions.
34 changes: 12 additions & 22 deletions DSCResources/MSFT_xRegistryResource/MSFT_xRegistryResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#>

# Fallback message strings in en-US
DATA localizedData
data localizedData
{
# culture = "en-US"
ConvertFrom-StringData @'
Expand Down Expand Up @@ -40,7 +40,7 @@ DATA localizedData
}

# Commented-out until more languages are supported
# Import-LocalizedData LocalizedData -filename MSFT_xRegistryResource.strings.psd1
# Import-LocalizedData LocalizedData -FileName MSFT_xRegistryResource.strings.psd1

<#
.SYNOPSIS
Expand Down Expand Up @@ -204,7 +204,7 @@ function Get-TargetResource
Special-case: Used only as a boolean flag (along with ValueData) to determine
if the target entity is the Default Value or the key itself.
#>
[ValidateSet('String', 'Binary', 'Dword', 'Qword', 'MultiString', 'ExpandString')]
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
[System.String]
$ValueType
)
Expand All @@ -226,7 +226,8 @@ function Get-TargetResource

if ($retVal.Ensure -eq 'Present')
{
[System.String[]]$retVal.ValueData += $retVal.Data
$retVal.ValueData = [System.String[]]@()
$retVal.ValueData += $retVal.Data

if ($retVal.ValueType -ieq 'MultiString')
{
Expand Down Expand Up @@ -303,7 +304,7 @@ function Set-TargetResource
[System.String[]]
$ValueData = @(),

[ValidateSet('String', 'Binary', 'Dword', 'Qword', 'MultiString', 'ExpandString')]
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
[System.String]
$ValueType = 'String',

Expand Down Expand Up @@ -474,12 +475,7 @@ function Set-TargetResource
{
try
{
# Formulate hiveName and subkeyName compatible with .NET APIs
$hiveName = $keyInfo.Data.PSDrive.Root.Replace('_','').Replace('HKEY','')
$subkeyName = $keyInfo.Data.Name.Substring($keyInfo.Data.Name.IndexOf('\')+1)

# Finally remove the subkeytree
[Microsoft.Win32.Registry]::$hiveName.DeleteSubKeyTree($subkeyName)
$null = Remove-Item -Path $Key -Recurse -Force
}
catch [System.Exception]
{
Expand Down Expand Up @@ -521,13 +517,7 @@ function Set-TargetResource
{
try
{
# Formulate hiveName and subkeyName compatible with .NET APIs
$hiveName = $keyInfo.Data.PSDrive.Root.Replace('_','').Replace('HKEY','')
$subkeyName = $keyInfo.Data.Name.Substring($keyInfo.Data.Name.IndexOf('\')+1)

# Finally open the subkey and remove the RegValue in subkey
$subkey = [Microsoft.Win32.Registry]::$hiveName.OpenSubKey($subkeyName, $true)
$subkey.DeleteValue($ValueName)
$null = Remove-ItemProperty -Path $Key -Name $ValueName -Force

}
catch [System.Exception]
Expand Down Expand Up @@ -604,7 +594,7 @@ function Test-TargetResource
[System.String[]]
$ValueData = @(),

[ValidateSet('String', 'Binary', 'Dword', 'Qword', 'MultiString', 'ExpandString')]
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
[System.String]
$ValueType = 'String',

Expand Down Expand Up @@ -1287,7 +1277,7 @@ function Convert-ByteArrayToHexString
)

$retString = ''
$Data | ForEach-Object { $retString += ('{0:x}' -f $_) }
$Data | ForEach-Object { $retString += ('{0:x2}' -f $_) }

return $retString
}
Expand Down Expand Up @@ -1464,7 +1454,7 @@ function Compare-ValueData
# Special case for binary comparison (do hex-string comparison)
if ($ValueType -ieq 'Binary')
{
$specifiedData = $ValueData[0]
$specifiedData = $ValueData[0].PadLeft($retrievedData.Length, '0')
}

# If the ValueType is not multistring, do a simple comparison
Expand Down Expand Up @@ -1498,4 +1488,4 @@ function Compare-ValueData
return $true
}

Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource
Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class MSFT_xRegistryResource : OMI_BaseResource
[Key] string Key;
[Key] string ValueName;
[Write] string ValueData[];
[Write,ValueMap{"String", "Binary", "Dword", "Qword", "MultiString", "ExpandString"},Values{"String", "Binary", "Dword", "Qword", "MultiString", "ExpandString"}] string ValueType;
[Write,ValueMap{"String", "Binary", "DWord", "QWord", "MultiString", "ExpandString"},Values{"String", "Binary", "DWord", "QWord", "MultiString", "ExpandString"}] string ValueType;
[Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[Write] boolean Hex;
[Write] boolean Force;
Expand Down
10 changes: 6 additions & 4 deletions HighQualityResourceModulePlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The PSDesiredStateConfiguration High Quality Resource Module will consist of the
- WindowsOptionalFeatureSet

## Progress

- [x] [1. Port In-Box Only Resources](#port-in-box-only-resources)
- [x] Environment
- [x] GroupSet
Expand All @@ -41,13 +42,14 @@ The PSDesiredStateConfiguration High Quality Resource Module will consist of the
- [x] Group
- [x] Package
- [X] Process
- [ ] Registry (In Progress)
- [x] Registry
- [x] Service
- [ ] WindowsOptionalFeature
- [ ] [3. Resolve Nano Server vs. Full Server Resources](#resolve-nano-server-vs-full-server-resources)
- [ ] WindowsOptionalFeature (In Progress)
- [x] [3. Resolve Nano Server vs. Full Server Resources](#resolve-nano-server-vs-full-server-resources)
The general consensus is to leave the if-statements for now.
- [ ] [4. Update the Resource Module to a High Quality Resource Module](#update-the-resource-module-to-a-high-quality-resource-module)
- [ ] 1. Fix PSSA issues per the [DSC Resource Kit PSSA Rule Severity List](https://github.com/PowerShell/DscResources/blob/master/PSSARuleSeverities.md).
- [ ] 2. Ensure unit tests are present for each resource with more than 70% code coverage.
- [ ] 2. Ensure unit tests are present for each resource with more than 70% code coverage. (In Progress)
- [ ] 3. Ensure examples run correctly, work as expected, and are documented clearly.
- [ ] 4. Ensure clear documentation is provided.
- [ ] 5. Ensure the PSDesiredStateConfiguration module follows the standard DSC Resource Kit module format.
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
* **xGroup** provides a mechanism to manage local groups on the target node.
* **xFileUpload** is a composite resource which ensures that local files exist on an SMB share.
* **xWindowsOptionalFeature** configures optional Windows features.
* **xRegistry** is a copy of the built-in Registry resource, with some small bug fixes.
* **xRegistry** provides a mechanism to manage registry keys and values on a target node.
* **xEnvironment** configures and manages environment variables.
* **xWindowsFeature** provides a mechanism to ensure that roles and features are added or removed on a target node.
* **xScript** provides a mechanism to run Windows PowerShell script blocks on target nodes.
Expand Down Expand Up @@ -166,8 +166,15 @@ Domain members may be specified using domain\name or User Principal Name (UPN) f

### xRegistry

This is a copy of the built-in Registry resource from the PSDesiredStateConfiguration module, with one small change: it now supports
registry keys whose names contain forward slashes.
xRegistry provides a mechanism to manage registry keys and values on a target node.

* **[String] Key** _(Key)_: Indicates the path of the registry key for which you want to ensure a specific state. This path must include the hive.
* **[String] ValueName** _(Key)_: Indicates the name of the registry value.
* **[String] Ensure** _(Write)_: Indicates if the key and value exist. To ensure that they do, set this property to "Present". To ensure that they do not exist, set the property to "Absent". The default value is "Present". { *Present* | Absent }.
* **[String] ValueData** _(Write)_: The data for the registry value.
* **[String] ValueType** _(Write)_: Indicates the type of the value. { String | Binary | DWord | QWord | MultiString | ExpandString }
* **[Boolean] Hex** _(Write)_: Indicates if data will be expressed in hexadecimal format. If specified, the DWORD/QWORD value data is presented in hexadecimal format. Not valid for other types. The default value is $false.
* **[Boolean] Force** _(Write)_: If the specified registry key is present, Force overwrites it with the new value.

### xWindowsOptionalFeature
Note: _the xWindowsOptionalFeature is only supported on Windows client or Windows Server 2012 (and later) SKUs._
Expand Down Expand Up @@ -348,6 +355,9 @@ These parameters will be the same for each Windows optional feature in the set.
* Fixed PSSA and style issues
* Renamed internal functions to follow verb-noun format
* Decorated all functions with comment-based help
* Merged with in-box Registry
* Fixed registry key and value removal
* Added unit tests
* xWindowsOptionalFeature:
* Cleaned up resource (PSSA issues, formatting, etc.)
* Added example script
Expand Down
47 changes: 0 additions & 47 deletions Tests/MSFT_xRegistryResource.Tests.ps1

This file was deleted.

Loading

0 comments on commit e907b85

Please sign in to comment.