Skip to content

Commit c0a6075

Browse files
authored
Merge pull request #165 from PowerShell/dev
Release of version 5.1.0.0 of ComputerManagementDsc
2 parents 8f9a482 + 4b2f827 commit c0a6075

20 files changed

+1243
-106
lines changed

.vscode/RunAllTests.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[string] $repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path)
2-
if ( (-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests'))) -or `
3-
(-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
1+
$repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path)
2+
$dscResourceTestsPath = Join-Path -Path $repoRoot -ChildPath '\Modules\ComputerManagementDsc\DSCResource.Tests\'
3+
4+
if ((-not (Test-Path -Path $dscResourceTestsPath)) -or `
5+
(-not (Test-Path -Path (Join-Path -Path $dscResourceTestsPath -ChildPath 'TestHelper.psm1'))))
46
{
5-
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $repoRoot -ChildPath '\DSCResource.Tests\'))
7+
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', $dscResourceTestsPath)
68
}
79

8-
Import-Module (Join-Path $PSScriptRoot "..\Tests\TestHarness.psm1" -Resolve)
9-
$dscTestsPath = Join-Path -Path $PSScriptRoot `
10-
-ChildPath "..\Modules\ComputerManagementDsc\DscResource.Tests\Meta.Tests.ps1"
10+
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\Tests\TestHarness.psm1' -Resolve)
11+
$dscTestsPath = Join-Path -Path $dscResourceTestsPath -ChildPath 'Meta.Tests.ps1'
1112
Invoke-TestHarness -DscTestsPath $dscTestsPath

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## Unreleased
44

5+
## 5.1.0.0
6+
7+
- TimeZone:
8+
- Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone)
9+
and renamed to TimeZone - fixes [Issue #157](https://github.com/PowerShell/ComputerManagementDsc/issues/157).
10+
- Moved Test-Command from ComputerManagementDsc.ResourceHelper to
11+
ComputerManagementDsc.Common module to match what TimeZone requires.
12+
It was not exported in ComputerManagementDsc.ResourceHelper and not
13+
used.
14+
515
## 5.0.0.0
616

717
- BREAKING CHANGE:

Modules/ComputerManagementDsc/ComputerManagementDsc.psd1

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
# Version number of this module.
3-
moduleVersion = '5.0.0.0'
3+
moduleVersion = '5.1.0.0'
44

55
# ID used to uniquely identify this module
66
GUID = 'B5004952-489E-43EA-999C-F16A25355B89'
@@ -49,17 +49,13 @@ PrivateData = @{
4949
# IconUri = ''
5050

5151
# ReleaseNotes of this module
52-
ReleaseNotes = '- BREAKING CHANGE:
53-
- Renamed ComputerManagement to ComputerManagementDsc - fixes [Issue 119](https://github.com/PowerShell/ComputerManagementDsc/issues/119).
54-
- Changed all MSFT\_xResourceName to MSFT\_ResourceName.
55-
- Updated DSCResources, Examples, Modules and Tests with new naming.
56-
- Updated Year to 2018 in License and Manifest.
57-
- Updated README.md from xComputerManagement to ComputerManagementDsc.
58-
- OfflineDomainJoin:
59-
- Cleaned up spacing in strings file to make consistent with other
60-
resources.
61-
- VirtualMemory:
62-
- Converted strings to single quotes in integration test.
52+
ReleaseNotes = '- TimeZone:
53+
- Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone)
54+
and renamed to TimeZone - fixes [Issue 157](https://github.com/PowerShell/ComputerManagementDsc/issues/157).
55+
- Moved Test-Command from ComputerManagementDsc.ResourceHelper to
56+
ComputerManagementDsc.Common module to match what TimeZone requires.
57+
It was not exported in ComputerManagementDsc.ResourceHelper and not
58+
used.
6359
6460
'
6561

@@ -68,3 +64,4 @@ PrivateData = @{
6864
} # End of PrivateData hashtable
6965
}
7066

67+
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'
2+
3+
# Import the ComputerManagementDsc Common Modules
4+
Import-Module -Name (Join-Path -Path $modulePath `
5+
-ChildPath (Join-Path -Path 'ComputerManagementDsc.Common' `
6+
-ChildPath 'ComputerManagementDsc.Common.psm1'))
7+
8+
# Import the ComputerManagementDsc Resource Helper Module
9+
Import-Module -Name (Join-Path -Path $modulePath `
10+
-ChildPath (Join-Path -Path 'ComputerManagementDsc.ResourceHelper' `
11+
-ChildPath 'ComputerManagementDsc.ResourceHelper.psm1'))
12+
13+
# Import Localization Strings.
14+
$LocalizedData = Get-LocalizedData `
15+
-ResourceName 'MSFT_TimeZone' `
16+
-ResourcePath (Split-Path -Parent $script:MyInvocation.MyCommand.Path)
17+
18+
<#
19+
.SYNOPSIS
20+
Returns the current time zone of the node.
21+
22+
.PARAMETER IsSingleInstance
23+
Specifies the resource is a single instance, the value must be 'Yes'.
24+
25+
.PARAMETER TimeZone
26+
Specifies the time zone.
27+
#>
28+
function Get-TargetResource
29+
{
30+
[CmdletBinding()]
31+
[OutputType([Hashtable])]
32+
param
33+
(
34+
[Parameter(Mandatory = $true)]
35+
[ValidateSet('Yes')]
36+
[System.String]
37+
$IsSingleInstance,
38+
39+
[Parameter(Mandatory = $true)]
40+
[ValidateNotNullOrEmpty()]
41+
[System.String]
42+
$TimeZone
43+
)
44+
45+
Write-Verbose -Message ($LocalizedData.GettingTimeZoneMessage)
46+
47+
# Get the current time zone Id.
48+
$currentTimeZone = Get-TimeZoneId
49+
50+
$returnValue = @{
51+
IsSingleInstance = 'Yes'
52+
TimeZone = $currentTimeZone
53+
}
54+
55+
# Output the target resource.
56+
return $returnValue
57+
}
58+
59+
<#
60+
.SYNOPSIS
61+
Sets the current time zone of the node.
62+
63+
.PARAMETER IsSingleInstance
64+
Specifies the resource is a single instance, the value must be 'Yes'.
65+
66+
.PARAMETER TimeZone
67+
Specifies the time zone.
68+
#>
69+
function Set-TargetResource
70+
{
71+
[CmdletBinding()]
72+
param
73+
(
74+
[Parameter(Mandatory = $true)]
75+
[ValidateSet('Yes')]
76+
[System.String]
77+
$IsSingleInstance,
78+
79+
[Parameter(Mandatory = $true)]
80+
[ValidateNotNullOrEmpty()]
81+
[System.String]
82+
$TimeZone
83+
)
84+
85+
$currentTimeZone = Get-TimeZoneId
86+
87+
if ($currentTimeZone -ne $TimeZone)
88+
{
89+
Write-Verbose -Message ($LocalizedData.SettingTimeZoneMessage)
90+
Set-TimeZoneId -TimeZone $TimeZone
91+
}
92+
else
93+
{
94+
Write-Verbose -Message ($LocalizedData.TimeZoneAlreadySetMessage -f $TimeZone)
95+
}
96+
}
97+
98+
<#
99+
.SYNOPSIS
100+
Tests the current time zone of the node.
101+
102+
.PARAMETER IsSingleInstance
103+
Specifies the resource is a single instance, the value must be 'Yes'.
104+
105+
.PARAMETER TimeZone
106+
Specifies the time zone.
107+
#>
108+
function Test-TargetResource
109+
{
110+
[CmdletBinding()]
111+
[OutputType([System.Boolean])]
112+
param
113+
(
114+
[Parameter(Mandatory = $true)]
115+
[ValidateSet('Yes')]
116+
[System.String]
117+
$IsSingleInstance,
118+
119+
[Parameter(Mandatory = $true)]
120+
[ValidateNotNullOrEmpty()]
121+
[System.String]
122+
$TimeZone
123+
)
124+
125+
Write-Verbose -Message ($LocalizedData.TestingTimeZoneMessage)
126+
127+
return Test-TimeZoneId -TimeZoneId $TimeZone
128+
}
129+
130+
Export-ModuleMember -Function *-TargetResource
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[ClassVersion("1.0.0.0"), FriendlyName("TimeZone")]
2+
class MSFT_TimeZone : OMI_BaseResource
3+
{
4+
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
5+
[Required, Description("Specifies the TimeZone.")] String TimeZone;
6+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Description
2+
3+
The resource will use the `Get-TimeZone` cmdlet to get the current
4+
time zone. If `Get-TimeZone` is not available them CIM will be used to retrieve
5+
the current time zone. To update the time zone, .NET reflection will be used to
6+
update the time zone if required. If .NET reflection is not supported on the node
7+
(in the case of Nano Server) then tzutil.exe will be used to set the time zone.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# culture="en-US"
2+
ConvertFrom-StringData -StringData @'
3+
GettingTimeZoneMessage = Getting the time zone.
4+
SettingTimeZoneMessage = Setting the time zone.
5+
TimeZoneAlreadySetMessage = Time zone already set to {0}.
6+
TestingTimeZoneMessage = Testing the time zone.
7+
'@
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<#
2+
.EXAMPLE
3+
This example sets the current time zone on the node
4+
to 'Tonga Standard Time'.
5+
#>
6+
Configuration Example
7+
{
8+
param
9+
(
10+
[Parameter()]
11+
[System.String[]]
12+
$NodeName = 'localhost'
13+
)
14+
15+
Import-DSCResource -ModuleName ComputerManagementDsc
16+
17+
Node $NodeName
18+
{
19+
TimeZone TimeZoneExample
20+
{
21+
IsSingleInstance = 'Yes'
22+
TimeZone = 'Tonga Standard Time'
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)