Skip to content

Commit

Permalink
Merge pull request #158 from PlagueHO/Issue-157
Browse files Browse the repository at this point in the history
Merged xTimeZone and converted to HQRM - Fixes #157
  • Loading branch information
PlagueHO committed May 14, 2018
2 parents 134208a + dee21d9 commit a028421
Show file tree
Hide file tree
Showing 19 changed files with 1,232 additions and 94 deletions.
15 changes: 8 additions & 7 deletions .vscode/RunAllTests.ps1
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

- TimeZone:
- Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone)
and renamed to TimeZone - fixes [Issue #157](https://github.com/PowerShell/ComputerManagementDsc/issues/157).
- Moved Test-Command from ComputerManagementDsc.ResourceHelper to
ComputerManagementDsc.Common module to match what TimeZone requires.
It was not exported in ComputerManagementDsc.ResourceHelper and not
used.

## 5.0.0.0

- BREAKING CHANGE:
Expand Down
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
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;
};
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.
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.
'@
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'
}
}
}

0 comments on commit a028421

Please sign in to comment.