-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from PlagueHO/Issue-50-B
Add SystemLocale Resource - Fixes #50
- Loading branch information
Showing
12 changed files
with
520 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' | ||
|
||
# Import the ComputerManagementDsc Common Modules | ||
Import-Module -Name (Join-Path -Path $modulePath ` | ||
-ChildPath (Join-Path -Path 'ComputerManagementDsc.Common' ` | ||
-ChildPath 'ComputerManagementDsc.Common.psm1')) -Force | ||
|
||
# Import the ComputerManagementDsc Resource Helper Module | ||
Import-Module -Name (Join-Path -Path $modulePath ` | ||
-ChildPath (Join-Path -Path 'ComputerManagementDsc.Common' ` | ||
-ChildPath 'ComputerManagementDsc.Common.psm1')) | ||
|
||
# Import Localization Strings | ||
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SystemLocale' | ||
|
||
<# | ||
.SYNOPSIS | ||
Returns the current System Local on the node. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER SystemLocale | ||
Specifies the System Locale. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$SystemLocale | ||
) | ||
|
||
Write-Verbose -Message ( @( | ||
"$($MyInvocation.MyCommand): " | ||
$($script:localizedData.GettingSystemLocaleMessage) | ||
) -join '' ) | ||
|
||
# Get the current System Locale | ||
$currentSystemLocale = Get-WinSystemLocale ` | ||
-ErrorAction Stop | ||
|
||
# Generate the return object. | ||
$returnValue = @{ | ||
IsSingleInstance = $IsSingleInstance | ||
SystemLocale = $currentSystemLocale.Name | ||
} | ||
|
||
return $returnValue | ||
} # Get-TargetResource | ||
|
||
<# | ||
.SYNOPSIS | ||
Sets the current System Locale on the node. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER SystemLocale | ||
Specifies the System Locale. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
# Suppressing this rule because $global:DSCMachineStatus is used to trigger a reboot when there are pending changes. | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$SystemLocale | ||
) | ||
|
||
Write-Verbose -Message ( @( | ||
"$($MyInvocation.MyCommand): " | ||
$($script:localizedData.SettingSystemLocaleMessage) | ||
) -join '' ) | ||
|
||
# Get the current System Locale | ||
$currentSystemLocale = Get-WinSystemLocale ` | ||
-ErrorAction Stop | ||
|
||
if ($currentSystemLocale.Name -ne $SystemLocale) | ||
{ | ||
Set-WinSystemLocale ` | ||
-SystemLocale $SystemLocale ` | ||
-ErrorAction Stop | ||
|
||
$global:DSCMachineStatus = 1 | ||
|
||
Write-Verbose -Message ( @( | ||
"$($MyInvocation.MyCommand): " | ||
$($script:localizedData.SystemLocaleUpdatedMessage -f $SystemLocale) | ||
) -join '' ) | ||
} | ||
} # Set-TargetResource | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests if the current System Locale on the node needs to be changed. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER SystemLocale | ||
Specifies the System Locale. | ||
.OUTPUTS | ||
Returns false if the System Locale needs to be changed or true if it is correct. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$SystemLocale | ||
) | ||
|
||
Write-Verbose -Message ( @( | ||
"$($MyInvocation.MyCommand): " | ||
$($script:localizedData.TestingSystemLocaleMessage) | ||
) -join '' ) | ||
|
||
if (-not (Test-SystemLocaleValue -SystemLocale $SystemLocale)) | ||
{ | ||
New-InvalidArgumentException ` | ||
-Message ($script:localizedData.InvalidSystemLocaleError -f $SystemLocale) ` | ||
-ArgumentName 'SystemLocale' | ||
} # if | ||
|
||
# Get the current System Locale | ||
$currentSystemLocale = Get-WinSystemLocale ` | ||
-ErrorAction Stop | ||
|
||
if ($currentSystemLocale.Name -ne $SystemLocale) | ||
{ | ||
Write-Verbose -Message ( @( | ||
"$($MyInvocation.MyCommand): " | ||
$($script:localizedData.SystemLocaleParameterNeedsUpdateMessage -f ` | ||
$currentSystemLocale.Name,$SystemLocale) | ||
) -join '' ) | ||
|
||
return $false | ||
} | ||
return $true | ||
} # Test-TargetResource | ||
|
||
<# | ||
.SYNOPSIS | ||
Checks the provided System Locale against the list of valid cultures. | ||
.PARAMETER SystemLocale | ||
The System Locale to check the validitiy of. | ||
#> | ||
function Test-SystemLocaleValue | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$SystemLocale | ||
) | ||
|
||
$validCultures = [System.Globalization.CultureInfo]::GetCultures(` | ||
[System.Globalization.CultureTypes]::AllCultures` | ||
).name | ||
|
||
return ($SystemLocale -in $validCultures) | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("SystemLocale")] | ||
class MSFT_SystemLocale : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; | ||
[Required, Description("Specifies the System Locale.")] String SystemLocale; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Description | ||
|
||
Ths resource is used set the system locale on a Windows machine. | ||
|
||
To get a list of valid Windows System Locales use the command: | ||
`[System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::AllCultures).name` | ||
|
||
If the System Locale is changed by this resource, it will require the node | ||
to reboot. If the LCM is not configured to allow restarting, the configuration | ||
will not be able to be applied until a manual restart occurs. |
9 changes: 9 additions & 0 deletions
9
DSCResources/MSFT_SystemLocale/en-US/MSFT_SystemLocale.strings.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# culture="en-US" | ||
ConvertFrom-StringData -StringData @' | ||
GettingSystemLocaleMessage = Getting Windows system locale. | ||
SettingSystemLocaleMessage = Setting Windows system locale. | ||
SystemLocaleUpdatedMessage = Windows system locale updated to "{0}". A system restart is required. | ||
TestingSystemLocaleMessage = Testing Windows system locale. | ||
SystemLocaleParameterNeedsUpdateMessage = Windows system locale is "{0}" but should be "{1}". Change required. | ||
InvalidSystemLocaleError = The Windows system locale "{0}" is invalid. | ||
'@ |
44 changes: 44 additions & 0 deletions
44
Examples/Resources/SystemLocale/1-SystemLocale_SetSystemLocale_Config.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<#PSScriptInfo | ||
.VERSION 1.0.0 | ||
.GUID 66476d02-bd04-4d5d-ac49-d64724716f41 | ||
.AUTHOR Microsoft Corporation | ||
.COMPANYNAME Microsoft Corporation | ||
.COPYRIGHT (c) Microsoft Corporation. All rights reserved. | ||
.TAGS DSCConfiguration | ||
.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE | ||
.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc | ||
.ICONURI | ||
.EXTERNALMODULEDEPENDENCIES | ||
.REQUIREDSCRIPTS | ||
.EXTERNALSCRIPTDEPENDENCIES | ||
.RELEASENOTES First version. | ||
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core | ||
#> | ||
|
||
#Requires -module ComputerManagementDsc | ||
|
||
<# | ||
.DESCRIPTION | ||
This example will set the System Locale of LocalHost to 'ja-JP'. | ||
To use this example, run it using PowerShell. | ||
#> | ||
Configuration SystemLocale_SetSystemLocale_Config | ||
{ | ||
param | ||
( | ||
[Parameter()] | ||
[System.String[]] | ||
$NodeName = 'localhost' | ||
) | ||
|
||
Import-DSCResource -ModuleName ComputerManagementDsc | ||
|
||
Node $NodeName | ||
{ | ||
SystemLocale SystemLocaleExample | ||
{ | ||
IsSingleInstance = 'Yes' | ||
SystemLocale = 'ja-JP' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.