Skip to content

Commit b411148

Browse files
committed
add logic to address ASCII default
1 parent 294d9d0 commit b411148

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.psm1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)