-
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 #158 from PlagueHO/Issue-157
Merged xTimeZone and converted to HQRM - Fixes #157
- Loading branch information
Showing
19 changed files
with
1,232 additions
and
94 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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
[string] $repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path) | ||
if ( (-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests'))) -or ` | ||
(-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) | ||
$repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path) | ||
$dscResourceTestsPath = Join-Path -Path $repoRoot -ChildPath '\Modules\ComputerManagementDsc\DSCResource.Tests\' | ||
|
||
if ((-not (Test-Path -Path $dscResourceTestsPath)) -or ` | ||
(-not (Test-Path -Path (Join-Path -Path $dscResourceTestsPath -ChildPath 'TestHelper.psm1')))) | ||
{ | ||
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $repoRoot -ChildPath '\DSCResource.Tests\')) | ||
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', $dscResourceTestsPath) | ||
} | ||
|
||
Import-Module (Join-Path $PSScriptRoot "..\Tests\TestHarness.psm1" -Resolve) | ||
$dscTestsPath = Join-Path -Path $PSScriptRoot ` | ||
-ChildPath "..\Modules\ComputerManagementDsc\DscResource.Tests\Meta.Tests.ps1" | ||
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\Tests\TestHarness.psm1' -Resolve) | ||
$dscTestsPath = Join-Path -Path $dscResourceTestsPath -ChildPath 'Meta.Tests.ps1' | ||
Invoke-TestHarness -DscTestsPath $dscTestsPath |
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
130 changes: 130 additions & 0 deletions
130
Modules/ComputerManagementDsc/DSCResources/MSFT_TimeZone/MSFT_TimeZone.psm1
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,130 @@ | ||
$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')) | ||
|
||
# Import the ComputerManagementDsc Resource Helper Module | ||
Import-Module -Name (Join-Path -Path $modulePath ` | ||
-ChildPath (Join-Path -Path 'ComputerManagementDsc.ResourceHelper' ` | ||
-ChildPath 'ComputerManagementDsc.ResourceHelper.psm1')) | ||
|
||
# Import Localization Strings. | ||
$LocalizedData = Get-LocalizedData ` | ||
-ResourceName 'MSFT_TimeZone' ` | ||
-ResourcePath (Split-Path -Parent $script:MyInvocation.MyCommand.Path) | ||
|
||
<# | ||
.SYNOPSIS | ||
Returns the current time zone of the node. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER TimeZone | ||
Specifies the time zone. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$TimeZone | ||
) | ||
|
||
Write-Verbose -Message ($LocalizedData.GettingTimeZoneMessage) | ||
|
||
# Get the current time zone Id. | ||
$currentTimeZone = Get-TimeZoneId | ||
|
||
$returnValue = @{ | ||
IsSingleInstance = 'Yes' | ||
TimeZone = $currentTimeZone | ||
} | ||
|
||
# Output the target resource. | ||
return $returnValue | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Sets the current time zone of the node. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER TimeZone | ||
Specifies the time zone. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$TimeZone | ||
) | ||
|
||
$currentTimeZone = Get-TimeZoneId | ||
|
||
if ($currentTimeZone -ne $TimeZone) | ||
{ | ||
Write-Verbose -Message ($LocalizedData.SettingTimeZoneMessage) | ||
Set-TimeZoneId -TimeZone $TimeZone | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message ($LocalizedData.TimeZoneAlreadySetMessage -f $TimeZone) | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests the current time zone of the node. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER TimeZone | ||
Specifies the time zone. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$TimeZone | ||
) | ||
|
||
Write-Verbose -Message ($LocalizedData.TestingTimeZoneMessage) | ||
|
||
return Test-TimeZoneId -TimeZoneId $TimeZone | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
6 changes: 6 additions & 0 deletions
6
Modules/ComputerManagementDsc/DSCResources/MSFT_TimeZone/MSFT_TimeZone.schema.mof
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("TimeZone")] | ||
class MSFT_TimeZone : 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 TimeZone.")] String TimeZone; | ||
}; |
7 changes: 7 additions & 0 deletions
7
Modules/ComputerManagementDsc/DSCResources/MSFT_TimeZone/README.md
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,7 @@ | ||
# Description | ||
|
||
The resource will use the `Get-TimeZone` cmdlet to get the current | ||
time zone. If `Get-TimeZone` is not available them CIM will be used to retrieve | ||
the current time zone. To update the time zone, .NET reflection will be used to | ||
update the time zone if required. If .NET reflection is not supported on the node | ||
(in the case of Nano Server) then tzutil.exe will be used to set the time zone. |
7 changes: 7 additions & 0 deletions
7
Modules/ComputerManagementDsc/DSCResources/MSFT_TimeZone/en-us/MSFT_TimeZone.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,7 @@ | ||
# culture="en-US" | ||
ConvertFrom-StringData -StringData @' | ||
GettingTimeZoneMessage = Getting the time zone. | ||
SettingTimeZoneMessage = Setting the time zone. | ||
TimeZoneAlreadySetMessage = Time zone already set to {0}. | ||
TestingTimeZoneMessage = Testing the time zone. | ||
'@ |
25 changes: 25 additions & 0 deletions
25
Modules/ComputerManagementDsc/Examples/Resources/TimeZone/1-SetTimeZone.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,25 @@ | ||
<# | ||
.EXAMPLE | ||
This example sets the current time zone on the node | ||
to 'Tonga Standard Time'. | ||
#> | ||
Configuration Example | ||
{ | ||
param | ||
( | ||
[Parameter()] | ||
[System.String[]] | ||
$NodeName = 'localhost' | ||
) | ||
|
||
Import-DSCResource -ModuleName ComputerManagementDsc | ||
|
||
Node $NodeName | ||
{ | ||
TimeZone TimeZoneExample | ||
{ | ||
IsSingleInstance = 'Yes' | ||
TimeZone = 'Tonga Standard Time' | ||
} | ||
} | ||
} |
Oops, something went wrong.