|
| 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 |
0 commit comments