8
8
if ($PSVersionTable.PSVersion.Major -gt 5 ) {
9
9
$PSDesiredStateConfiguration = Import-Module - Path ' ../PSDesiredStateConfiguration/2.0.7/PSDesiredStateConfiguration.psd1' - Force - PassThru
10
10
}
11
+ else {
12
+ $env: PSModulePath += " ;$env: windir \System32\WindowsPowerShell\v1.0\Modules"
13
+ $PSDesiredStateConfiguration = Import-Module - Name ' PSDesiredStateConfiguration' - RequiredVersion ' 1.1' - Force - PassThru - ErrorAction stop - ErrorVariable $importModuleError
14
+ if (-not [string ]::IsNullOrEmpty($importModuleError )) {
15
+ $trace = @ {' Debug' = ' ERROR: Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError } | ConvertTo-Json - Compress
16
+ $host.ui.WriteErrorLine ($trace )
17
+ }
18
+ }
11
19
12
20
<# public function Invoke-DscCacheRefresh
13
21
. SYNOPSIS
@@ -28,17 +36,7 @@ function Invoke-DscCacheRefresh {
28
36
[Object []]
29
37
$Module
30
38
)
31
- # for the WindowsPowerShell adapter, always use the version of PSDesiredStateConfiguration that ships in Windows
32
- if ($PSVersionTable.PSVersion.Major -le 5 ) {
33
- $psdscWindowsPath = " $env: windir \System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1"
34
- Import-Module $psdscWindowsPath - Force - ErrorAction stop - ErrorVariable $importModuleError
35
- if (-not [string ]::IsNullOrEmpty($importModuleError )) {
36
- $trace = @ {' Debug' = ' ERROR: Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError } | ConvertTo-Json - Compress
37
- $host.ui.WriteErrorLine ($trace )
38
- }
39
- $DSCVersion = [version ]' 1.1.0'
40
- }
41
-
39
+
42
40
# cache the results of Get-DscResource
43
41
[dscResourceCache []]$dscResourceCache = @ ()
44
42
@@ -72,7 +70,7 @@ function Invoke-DscCacheRefresh {
72
70
}
73
71
74
72
# we can't run this check in PSDesiredStateConfiguration 1.1 because the property doesn't exist
75
- if ( $DSCVersion -ge [ version ] ' 2.0.0 ' ) {
73
+ if ( $PSVersionTable .PSVersion.Major -le 5 ) {
76
74
# only support known dscResourceType
77
75
if ([dscResourceType ].GetEnumNames() -notcontains $dscResource.ImplementationDetail ) {
78
76
$trace = @ {' Debug' = ' WARNING: implementation detail not found: ' + $dscResource.ImplementationDetail } | ConvertTo-Json - Compress
@@ -90,7 +88,7 @@ function Invoke-DscCacheRefresh {
90
88
)
91
89
$DscResourceInfo = [DscResourceInfo ]::new()
92
90
$dscResource.PSObject.Properties | ForEach-Object - Process {
93
- if ($null -eq $_.Value ) {$_.Value = ' ' }
91
+ if ($null -eq $_.Value ) { $_.Value = ' ' }
94
92
$DscResourceInfo .$ ($_.Name ) = $_.Value
95
93
}
96
94
if ($dscResource.ModuleName ) {
@@ -182,16 +180,6 @@ function Get-ActualState {
182
180
[dscResourceCache []]$dscResourceCache
183
181
)
184
182
185
- # for the WindowsPowerShell adapter, always use the version of PSDesiredStateConfiguration that ships in Windows
186
- if ($PSVersionTable.PSVersion.Major -le 5 ) {
187
- $psdscWindowsPath = " $env: windir \System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1"
188
- Import-Module $psdscWindowsPath - Force - ErrorAction stop - ErrorVariable $importModuleError
189
- if (-not [string ]::IsNullOrEmpty($importModuleError )) {
190
- $trace = @ {' Debug' = ' ERROR: Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError } | ConvertTo-Json - Compress
191
- $host.ui.WriteErrorLine ($trace )
192
- }
193
- }
194
-
195
183
$osVersion = [System.Environment ]::OSVersion.VersionString
196
184
$trace = @ {' Debug' = ' OS version: ' + $osVersion } | ConvertTo-Json - Compress
197
185
$host.ui.WriteErrorLine ($trace )
@@ -298,11 +286,9 @@ function Get-ActualState {
298
286
299
287
# using the cmdlet from PSDesiredStateConfiguration module in Windows
300
288
try {
301
- $env: PSModulePath += " ;$env: windir \System32\WindowsPowerShell\v1.0\Modules"
302
- $PSDesiredStateConfiguration = Import-Module - Name ' PSDesiredStateConfiguration' - RequiredVersion ' 1.1' - Force - PassThru
303
- $getResult = $PSDesiredStateConfiguration.invoke ({param ($Name , $Property ) Invoke-DscResource - Name $Name - Method Get - ModuleName @ {ModuleName = ' PSDesiredStateConfiguration' ; ModuleVersion = ' 1.1' } - Property $Property }, $cachedDscResourceInfo.Name , $property )
289
+ $getResult = $PSDesiredStateConfiguration.invoke ({ param ($Name , $Property ) Invoke-DscResource - Name $Name - Method Get - ModuleName @ {ModuleName = ' PSDesiredStateConfiguration' ; ModuleVersion = ' 1.1' } - Property $Property }, $cachedDscResourceInfo.Name , $property )
304
290
305
- $trace = @ {' Debug' = ' TEMP output: ' + $ ($getResult | convertto-json - depth 10 - Compress) } | ConvertTo-Json - Compress
291
+ $trace = @ {' Debug' = ' TEMP output: ' + $ ($getResult | ConvertTo-Json - Depth 10 - Compress) } | ConvertTo-Json - Compress
306
292
$host.ui.WriteErrorLine ($trace )
307
293
308
294
# only return DSC properties from the Cim instance
0 commit comments