Skip to content

Commit

Permalink
Merge pull request #64 from PowerShell/dev
Browse files Browse the repository at this point in the history
Merging release pull request
  • Loading branch information
KarolKaczmarek committed Feb 2, 2016
2 parents 7946497 + 926390d commit 3742e73
Show file tree
Hide file tree
Showing 12 changed files with 1,631 additions and 22 deletions.
1,132 changes: 1,132 additions & 0 deletions DSCResources/MSFT_xRegistryResource/MSFT_xRegistryResource.psm1

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ClassVersion("1.0.0"), FriendlyName("xRegistry")]
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{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[Write] boolean Hex;
[Write] boolean Force;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma namespace("\\\\.\\root\\default")
instance of __namespace{ name="MS_409";};
#pragma namespace("\\\\.\\root\\default\\MS_409")

[Description("This resource is used to perform Get, Set and Test operations on Windows Registry.") : Amended,AMENDMENT, LOCALE(0x0409)]
class MSFT_xRegistryResource : OMI_BaseResource
{
[Key,Description("Path of the registry key.\n") : Amended] string Key;
[Key,Description("Name of the registry key value.\n") : Amended] string ValueName;
[Description("Data of the registry key value.\n") : Amended] string ValueData[];
[Description("Type of the registry key data.\n") : Amended] string ValueType;
[Description("Enumerated value describing if the environment variable should exist on target machine.\nPresent {default} \nAbsent \n") : Amended] string Ensure;
[Description("Flag to identify Hex or Decimal values.\n") : Amended] boolean Hex;
[Description("Flag to specify forced execution.\n") : Amended] boolean Force;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Localized 10/30/2015 03:58 AM (GMT) 303:4.80.0411 MSFT_xRegistryResource.strings.psd1
# Localized resources for MSFT_xRegistryResource

ConvertFrom-StringData @'
###PSLOC
ParameterValueInvalid=(ERROR) Parameter '{0}' has an invalid value '{1}' for type '{2}'
InvalidPSDriveSpecified=(ERROR) Invalid PSDrive '{0}' specified in registry key '{1}'
InvalidRegistryHiveSpecified=(ERROR) Invalid registry hive was specified in registry key '{0}'
SetRegValueFailed=(ERROR) Failed to set registry key value '{0}' to value '{1}' of type '{2}'
SetRegValueUnchanged=(UNCHANGED) No change to registry key value '{0}' containing '{1}'
SetRegKeyUnchanged=(UNCHANGED) No change to registry key '{0}'
SetRegValueSucceeded=(SET) Set registry key value '{0}' to '{1}' of type '{2}'
SetRegKeySucceeded=(SET) Create registry key '{0}'
SetRegKeyFailed=(ERROR) Failed to created registry key '{0}'
RemoveRegKeyTreeFailed=(ERROR) Registry Key '{0}' has subkeys, cannot remove without Force flag
RemoveRegKeySucceeded=(REMOVAL) Registry key '{0}' removed
RemoveRegKeyFailed=(ERROR) Failed to remove registry key '{0}'
RemoveRegValueSucceeded=(REMOVAL) Registry key value '{0}' removed
RemoveRegValueFailed=(ERROR) Failed to remove registry key value '{0}'
RegKeyDoesNotExist=Registry key '{0}' does not exist
RegKeyExists=Registry key '{0}' exists
RegValueExists=Found registry key value '{0}' with type '{1}' and data '{2}'
RegValueDoesNotExist=Registry key value '{0}' does not exist
RegValueTypeMismatch=Registry key value '{0}' of type '{1}' does not exist
RegValueDataMismatch=Registry key value '{0}' of type '{1}' does not contain data '{2}'
DefaultValueDisplayName=(Default)
###PSLOC
'@
4 changes: 2 additions & 2 deletions DSCResources/MSFT_xRemoteFile/MSFT_xRemoteFile.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class MSFT_xRemoteFile : OMI_BaseResource
[Write, Description("User agent for the web request.")] String UserAgent;
[Write, EmbeddedInstance("MSFT_KeyValuePair"), Description("Headers of the web request.")] String Headers[];
[Write, EmbeddedInstance("MSFT_Credential"), Description("Specifies a user account that has permission to send the request.")] String Credential;
[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;
[Read, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}, Description("Says whether DestinationPath exists on the machine")] String Ensure;
[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;
[Read, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}, Description("Says whether DestinationPath exists on the machine")] String Ensure;
};


Expand Down
4 changes: 2 additions & 2 deletions DSCResources/MSFT_xServiceResource/MSFT_xServiceResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ function Set-TargetResource
}
if($PSBoundParameters.ContainsKey("Dependencies"))
{
$argumentsToNewService.Add("Dependencies", $Dependencies)
$argumentsToNewService.Add("DependsOn", $Dependencies)
}
try
{
New-Service @argumentsToNewService
}
catch
{
Write-Log -Message ("Error creating service `"$($argumentsToNewService["Name"])`"", $_.Exception.Message)
Write-Log -Message ("Error creating service `"$($argumentsToNewService["Name"])`"; Exception Message: $($_.Exception.Message)")
throw $_
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DATA localizedData
# culture = "en-US"
ConvertFrom-StringData @'
DismNotAvailable = PowerShell module Dism could not be imported.
NotAClientSku = This Resource is only available for Windows Client.
NotSupportedSku = This Resource is only available for Windows Client or Server 2012 (or later).
ElevationRequired = This Resource requires to be run as an Administrator.
ValidatingPrerequisites = Validating prerequisites...
CouldNotCovertFeatureState = Could not convert feature state '{0}' into Absent/Present.
Expand Down Expand Up @@ -155,11 +155,11 @@ function Set-TargetResource
{
if ($NoWindowsUpdateCheck)
{
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -LimitAccess
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -LimitAccess -NoRestart
}
else
{
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters
$feature = Dism\Enable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -NoRestart
}

Write-Verbose ($LocalizedData.FeatureInstalled -f $Name)
Expand All @@ -168,11 +168,11 @@ function Set-TargetResource
{
if ($RemoveFilesOnDisable)
{
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -Remove
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -Remove -NoRestart
}
else
{
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters
$feature = Dism\Disable-WindowsOptionalFeature -FeatureName $Name -Online -LogLevel $DismLogLevel @PSBoundParameters -NoRestart
}

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

## Indicate we need a restart as needed
if ($feature.RestartNeeded)
{
Write-Verbose $LocalizedData.RestartNeeded
Expand Down Expand Up @@ -234,12 +235,11 @@ function Test-TargetResource
{
$result = $Ensure -eq 'Absent'
}
if (($result.State -eq 'Disabled' -and $Ensure -eq 'Absent')`
-or ($result.State -eq 'Enabled' -and $Ensure -eq 'Present'))
if (($featureState.State -eq 'Disabled' -and $Ensure -eq 'Absent')`
-or ($featureState.State -eq 'Enabled' -and $Ensure -eq 'Present'))
{
$result = $true
}

Write-Debug ($LocalizedData.TestTargetResourceEndMessage -f $Name)
return $result
}
Expand All @@ -250,12 +250,12 @@ function ValidatePrerequisites
{
Write-Verbose $LocalizedData.ValidatingPrerequisites

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

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

# check that we are running elevated
Expand Down
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# xPSDesiredStateConfiguration

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

## Contributing
Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md).
Expand All @@ -18,7 +18,9 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
* **xRemoteFile** ensures the presence of remote files on a local machine.
* **xPackage** manages the installation of .msi and .exe packages.
* **xGroup** configures and manages local Windows groups
* **xFileUpload** is a composite resource which ensures that local files exist on an SMB share.
* **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.

### xArchive

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

### 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.

### xWindowsOptionalFeature
Note: _the xWindowsOptionalFeature is only supported on Windows client or Windows Server 2012 (and later) SKUs._

* **Name**: Name of the optional Windows feature.
* **Source**: Specifies the location of the files that are required to restore a feature that has been removed from the image.
- You can specify the Windows directory of a mounted image or a running Windows installation that is shared on the network.
- 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.
* **RemoveFilesOnDisable**: Removes the files for an optional feature without removing the feature's manifest from the image.
- Suported values: $true, $false.
- Default value: $false.
* **LogPath**: Specifies the full path and file name to log to.
- If not set, the default is %WINDIR%\Logs\Dism\dism.log.
* **Ensure**: Ensures that the feature is present or absent.
- Supported values: Present, Absent.
- Default Value: Present.
* **NoWindowsUpdateCheck**: Prevents DISM from contacting Windows Update (WU) when searching for the source files to restore a feature on an online image.
- Suported values: $true, $false.
- Default value: $false.
* **LogLevel**: Specifies the maximum output level shown in the logs.
- Suported values: ErrorsOnly, ErrorsAndWarning, ErrorsAndWarningAndInformation.
- Default value: ErrorsOnly.

## Versions

### Unreleased

### 3.7.0.0

* xService:
- Fixed a bug where 'Dependencies' property was not picked up and caused exception when set.
* xWindowsOptionalFeature:
- Fixed bug where Test-TargetResource method always failed.
- Added support for Windows Server 2012 (and later) SKUs.
* Added xRegistry resource

### 3.6.0.0
* Added CreateCheckRegValue parameter to xPackage resource
* Added MatchSource parameter to xRemoteFile resource
Expand Down
47 changes: 47 additions & 0 deletions Tests/MSFT_xRegistryResource.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
$ErrorActionPreference = 'Stop'

Get-Module MSFT_xRegistryResource | Remove-Module -Force
Import-Module $PSScriptRoot\..\DSCResources\MSFT_xRegistryResource\MSFT_xRegistryResource.psm1 -Prefix UnitTest

Describe 'MSFT_xRegistryResource' {
BeforeAll {
$rootPath = 'Software\__MSFT_xRegistryResource__'
$rootPathWithDrive = "HKCU:\$rootPath"
if (Test-Path -LiteralPath $rootPathWithDrive)
{
Remove-Item -LiteralPath $rootPathWithDrive -Recurse -Force
}

New-Item -Path $rootPathWithDrive
}

AfterAll {
if (Test-Path -LiteralPath $rootPathWithDrive)
{
Remove-Item -LiteralPath $rootPathWithDrive -Recurse -Force
}
}

It 'Supports keys containing forward slashes' {
$keyName = 'Test/Key'
$valueName = 'Testing'
$valueData = 'TestValue'

$scriptBlock = {
Set-UnitTestTargetResource -Key $rootPathWithDrive\$keyName `
-ValueName $valueName `
-ValueData $valueData `
-ValueType String `
-Force $true `
-ErrorAction Stop
}

$scriptBlock | Should Not Throw

$regKey = (Get-Item HKCU:\).OpenSubKey("$rootPath\$keyName")

$regKey | Should Not Be Null
$regKey.GetValue($valueName) | Should Be $valueData
}
}

Loading

0 comments on commit 3742e73

Please sign in to comment.