File tree Expand file tree Collapse file tree
DSCResources/DSR_KeyValuePairFile Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,11 +224,6 @@ function Set-TargetResource
224224 # The key value pair should exist
225225 $keyValuePair = ' {0}={1}{2}' -f $Name , $Text , $eolChars
226226
227- if ($PSBoundParameters.ContainsKey (' Encoding' ) -and ($Encoding -ne $fileEncoding ))
228- {
229- $fileProperties.Add (' Encoding' , $Encoding )
230- }
231-
232227 if ($results.Count -eq 0 )
233228 {
234229 # The key value pair was not found so add it to the end of the file
@@ -264,9 +259,6 @@ function Set-TargetResource
264259 {
265260 Write-Verbose - Message ($localizedData.FileEncodingNotInDesiredState -f `
266261 $fileEncoding , $Encoding )
267-
268- # Add encoding parameter and value to the hashtable
269- $fileProperties.add (' Encoding' , $Encoding )
270262 }
271263 }
272264 else
@@ -286,6 +278,13 @@ function Set-TargetResource
286278
287279 $fileProperties.Add (' Value' , $fileContent )
288280
281+ # Verify encoding is not set to the passed parameter or the default of ASCII
282+ if ($PSBoundParameters.ContainsKey (' Encoding' ) -and ($Encoding -ne ($fileEncoding -or ' ASCII' )))
283+ {
284+ # Add encoding parameter and value to the hashtable
285+ $fileProperties.Add (' Encoding' , $Encoding )
286+ }
287+
289288 Set-Content @fileProperties
290289}
291290
You can’t perform that action at this time.
0 commit comments