@@ -103,6 +103,9 @@ function Get-TargetResource
103103 . PARAMETER Secret
104104 The secret text to replace the text identified by the RegEx.
105105 Only used when Type is set to 'Secret'.
106+
107+ . PARAMETER AllowAppend
108+ Specifies to append text to the file being modified. Adds the ability to add a configuration entry.
106109#>
107110function Set-TargetResource
108111{
@@ -200,6 +203,9 @@ function Set-TargetResource
200203 . PARAMETER Secret
201204 The secret text to replace the text identified by the RegEx.
202205 Only used when Type is set to 'Secret'.
206+
207+ . PARAMETER AllowAppend
208+ Specifies to append text to the file being modified. Adds the ability to add a configuration entry.
203209#>
204210function Test-TargetResource
205211{
@@ -374,7 +380,7 @@ function Assert-ParametersValid
374380 The existing file content of the configuration file.
375381
376382 . PARAMETER Text
377- The text to replace the text identifed by the RegEx .
383+ The text to append to the end of the FileContent .
378384#>
379385function Add-ConfigurationEntry
380386{
@@ -391,17 +397,22 @@ function Add-ConfigurationEntry
391397 $Text
392398 )
393399
394- $stringBuilder = New-Object - TypeName System.Text.StringBuilder
395-
396- $fileContentArray = $FileContent.Trim () -split ' \n'
397-
398- foreach ($line in $fileContentArray )
400+ if ($FileContent -match ' \n$' -and $FileContent -notmatch ' \r\n$' )
399401 {
400- # Lets remove the return character since AppendLine() always adds one
401- $null = $stringBuilder .AppendLine ( $line -replace ' \r ' )
402+ # default Linux line ending
403+ $detectedNewLineFormat = " `n "
402404 }
405+ else
406+ {
407+ # default Windows line ending
408+ $detectedNewLineFormat = " `r`n "
409+ }
410+
411+ $stringBuilder = New-Object - TypeName System.Text.StringBuilder
403412
404- $null = $stringBuilder.AppendLine ($Text )
413+ $null = $stringBuilder.Append ($FileContent )
414+ $null = $stringBuilder.Append ($Text )
415+ $null = $stringBuilder.Append ($detectedNewLineFormat )
405416
406417 return $stringBuilder.ToString ()
407418}
0 commit comments