@@ -9,13 +9,13 @@ $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot
99
1010# Import the Storage Common Modules
1111Import-Module - Name (Join-Path - Path $modulePath `
12- - ChildPath (Join-Path - Path ' FileContentDsc.Common' `
13- - ChildPath ' FileContentDsc.Common.psm1' ))
12+ - ChildPath (Join-Path - Path ' FileContentDsc.Common' `
13+ - ChildPath ' FileContentDsc.Common.psm1' ))
1414
1515# Import the Storage Resource Helper Module
1616Import-Module - Name (Join-Path - Path $modulePath `
17- - ChildPath (Join-Path - Path ' FileContentDsc.ResourceHelper' `
18- - ChildPath ' FileContentDsc.ResourceHelper.psm1' ))
17+ - ChildPath (Join-Path - Path ' FileContentDsc.ResourceHelper' `
18+ - ChildPath ' FileContentDsc.ResourceHelper.psm1' ))
1919
2020# Import Localization Strings
2121$localizedData = Get-LocalizedData `
@@ -54,31 +54,32 @@ function Get-TargetResource
5454 $fileContent = Get-Content - Path $Path - Raw
5555
5656 Write-Verbose - Message ($localizedData.SearchForTextMessage -f `
57- $Path , $Search )
57+ $Path , $Search )
5858
5959 $text = ' '
6060
6161 # Search the file content for any matches
62- $results = [regex ]::Matches($fileContent , $Search )
63-
64- if ($results.Count -eq 0 ) {
62+ $results = [regex ]::Matches($fileContent , $Search )
63+
64+ if ($results.Count -eq 0 )
65+ {
6566 # No matches found - already in state
6667 Write-Verbose - Message ($localizedData.StringNotFoundMessage -f `
67- $Path , $Search )
68+ $Path , $Search )
6869 }
6970 else
7071 {
7172 $text = ($results.Value -join ' ,' )
7273
7374 Write-Verbose - Message ($localizedData.StringMatchFoundMessage -f `
74- $Path , $Search , $text )
75+ $Path , $Search , $text )
7576 } # if
7677
7778 return @ {
78- Path = $Path
79- Search = $Search
80- Type = ' Text'
81- Text = $text
79+ Path = $Path
80+ Search = $Search
81+ Type = ' Text'
82+ Text = $text
8283 }
8384}
8485
@@ -93,15 +94,15 @@ function Get-TargetResource
9394 The RegEx string to use to search the text file.
9495
9596 . PARAMETER Type
96- Specifies the value type to use as the replacement string.
97+ Specifies the value type to use as the replacement string. Defaults to 'Text'.
9798
9899 . PARAMETER Text
99100 The text to replace the text identifed by the RegEx.
100101 Only used when Type is set to 'Text'.
101102
102- . PARAMETER Password
103- The password to replace the text identified by the RegEx.
104- Only used when Type is set to 'Password '.
103+ . PARAMETER Secret
104+ The secret text to replace the text identified by the RegEx.
105+ Only used when Type is set to 'Secret '.
105106#>
106107function Set-TargetResource
107108{
@@ -121,7 +122,7 @@ function Set-TargetResource
121122 $Search ,
122123
123124 [Parameter ()]
124- [ValidateSet (' Text' , ' Password ' )]
125+ [ValidateSet (' Text' , ' Secret ' )]
125126 [String ]
126127 $Type = ' Text' ,
127128
@@ -132,31 +133,32 @@ function Set-TargetResource
132133 [Parameter ()]
133134 [System.Management.Automation.PSCredential ]
134135 [System.Management.Automation.Credential ()]
135- $Password
136+ $Secret
136137 )
137138
138139 Assert-ParametersValid @PSBoundParameters
139140
140141 $fileContent = Get-Content - Path $Path - Raw
141142
142- if ($Type -eq ' Password ' )
143+ if ($Type -eq ' Secret ' )
143144 {
144- Write-Verbose - Message ($localizedData.StringReplacePasswordMessage -f `
145- $Path )
145+ Write-Verbose - Message ($localizedData.StringReplaceSecretMessage -f `
146+ $Path )
146147
147- $Text = $Password .Password
148+ $Text = $Secret .GetNetworkCredential () .Password
148149 }
149150 else
150151 {
151152 Write-Verbose - Message ($localizedData.StringReplaceTextMessage -f `
152- $Path , $Text )
153+ $Path , $Text )
153154 } # if
154155
155- $fileContent = $fileContent -Replace $Search , $Text
156+ $fileContent = $fileContent -Replace $Search , $Text
156157
157158 Set-Content `
158159 - Path $Path `
159160 - Value $fileContent `
161+ - NoNewline `
160162 - Force
161163}
162164
@@ -171,15 +173,15 @@ function Set-TargetResource
171173 The RegEx string to use to search the text file.
172174
173175 . PARAMETER Type
174- Specifies the value type to use as the replacement string.
176+ Specifies the value type to use as the replacement string. Defaults to 'Text'.
175177
176178 . PARAMETER Text
177179 The text to replace the text identifed by the RegEx.
178180 Only used when Type is set to 'Text'.
179181
180- . PARAMETER Password
181- The password to replace the text identified by the RegEx.
182- Only used when Type is set to 'Password '.
182+ . PARAMETER Secret
183+ The secret text to replace the text identified by the RegEx.
184+ Only used when Type is set to 'Secret '.
183185#>
184186function Test-TargetResource
185187{
@@ -198,7 +200,7 @@ function Test-TargetResource
198200 $Search ,
199201
200202 [Parameter ()]
201- [ValidateSet (' Text' , ' Password ' )]
203+ [ValidateSet (' Text' , ' Secret ' )]
202204 [String ]
203205 $Type = ' Text' ,
204206
@@ -209,33 +211,34 @@ function Test-TargetResource
209211 [Parameter ()]
210212 [System.Management.Automation.PSCredential ]
211213 [System.Management.Automation.Credential ()]
212- $Password
214+ $Secret
213215 )
214216
215217 Assert-ParametersValid @PSBoundParameters
216218
217219 $fileContent = Get-Content - Path $Path - Raw
218220
219221 Write-Verbose - Message ($localizedData.SearchForTextMessage -f `
220- $Path , $Search )
222+ $Path , $Search )
221223
222224 # Search the file content for any matches
223- $results = [regex ]::Matches($fileContent , $Search )
225+ $results = [regex ]::Matches($fileContent , $Search )
224226
225- if ($results.Count -eq 0 ) {
227+ if ($results.Count -eq 0 )
228+ {
226229 # No matches found - already in state
227230 Write-Verbose - Message ($localizedData.StringNotFoundMessage -f `
228- $Path , $Search )
231+ $Path , $Search )
229232
230233 return $true
231234 }
232235
233236 # Flag to signal whether settings are correct
234237 [Boolean ] $desiredConfigurationMatch = $true
235238
236- if ($Type -eq ' Password ' )
239+ if ($Type -eq ' Secret ' )
237240 {
238- $Text = $Password .Password
241+ $Text = $Secret .Password
239242 } # if
240243
241244 foreach ($result in $results )
@@ -249,12 +252,12 @@ function Test-TargetResource
249252 if ($desiredConfigurationMatch )
250253 {
251254 Write-Verbose - Message ($localizedData.StringNoReplacementMessage -f `
252- $Path , $Search )
255+ $Path , $Search )
253256 }
254257 else
255258 {
256259 Write-Verbose - Message ($localizedData.StringReplacementRequiredMessage -f `
257- $Path , $Search )
260+ $Path , $Search )
258261 } # if
259262
260263 return $desiredConfigurationMatch
@@ -272,15 +275,15 @@ function Test-TargetResource
272275 The RegEx string to use to search the text file.
273276
274277 . PARAMETER Type
275- Specifies the value type to use as the replacement string.
278+ Specifies the value type to use as the replacement string. Defaults to 'Text'.
276279
277280 . PARAMETER Text
278281 The text to replace the text identifed by the RegEx.
279282 Only used when Type is set to 'Text'.
280283
281- . PARAMETER Password
282- The password to replace the text identified by the RegEx.
283- Only used when Type is set to 'Password '.
284+ . PARAMETER Secret
285+ The secret text to replace the text identified by the RegEx.
286+ Only used when Type is set to 'Secret '.
284287#>
285288function Assert-ParametersValid
286289{
@@ -299,7 +302,7 @@ function Assert-ParametersValid
299302 $Search ,
300303
301304 [Parameter ()]
302- [ValidateSet (' Text' , ' Password ' )]
305+ [ValidateSet (' Text' , ' Secret ' )]
303306 [String ]
304307 $Type = ' Text' ,
305308
@@ -310,7 +313,7 @@ function Assert-ParametersValid
310313 [Parameter ()]
311314 [System.Management.Automation.PSCredential ]
312315 [System.Management.Automation.Credential ()]
313- $Password
316+ $Secret
314317 )
315318
316319 # Does the file in path exist?
0 commit comments