DSCResources/DSC_ReplaceText/en-US/about_ReplaceText.help.txt
.NAME
ReplaceText .DESCRIPTION The resource is used to replace strings matching a regular expression in a text file. It can be used to replace strings matched with a regular expression with either a text string or a secret which is provided in the password of a credential object. .PARAMETER Path Key - String The path to the text file to replace the string in. .PARAMETER Search Key - String The RegEx string to use to search the text file. .PARAMETER Type Write - String Allowed values: Text, Secret Specifies the value type to use as the replacement string. Defaults to 'Text'. .PARAMETER Text Write - String The text to replace the text identified by the RegEx. Only used when Type is set to 'Text'. .PARAMETER Secret Write - Instance The secret text to replace the text identified by the RegEx. Only used when Type is set to 'Secret'. .PARAMETER AllowAppend Write - Boolean Specifies to append text to the file being modified. Adds the ability to add a configuration entry. .PARAMETER Encoding Write - String Allowed values: ASCII, BigEndianUnicode, BigEndianUTF32, UTF8, UTF32 Specifies the file encoding. Defaults to ASCII .EXAMPLE 1 Set all occrurances of the string `%secret%` to be the value in the password set in the parameter $Secret PSCredential object in the file `c:\inetpub\wwwroot\default.htm`. Configuration ReplaceText_ReplacePlainSecretText_Config { param ( [Parameter()] [ValidateNotNullorEmpty()] [PSCredential] $Secret ) Import-DSCResource -ModuleName FileContentDsc Node localhost { ReplaceText SetSecretText { Path = 'c:\inetpub\wwwroot\default.htm' Search = '%secret%' Type = 'Secret' Secret = $Secret } } } .EXAMPLE 2 Set all occrurances of the string `%appname%` to be Awesome App` in the file `c:\inetpub\wwwroot\default.htm`. Configuration ReplaceText_ReplacePlainText_Config { Import-DSCResource -ModuleName FileContentDsc Node localhost { ReplaceText SetText { Path = 'c:\inetpub\wwwroot\default.htm' Search = '%appname%' Type = 'Text' Text = 'Awesome App' } } } .EXAMPLE 3 Set all occrurances of a string matching the regular expression `<img src=['``"][a-zA-Z0-9.]*['``"]>` with the text `<img src="imgs/placeholder.jpg">` in the file `c:\inetpub\wwwroot\default.htm` Configuration ReplaceText_ReplaceRegexText_Config { Import-DSCResource -ModuleName FileContentDsc Node localhost { ReplaceText SetTextWithRegex { Path = 'c:\inetpub\wwwroot\default.htm' Search = "<img src=['`"][a-zA-Z0-9.]*['`"]>" Type = 'Text' Text = '<img src="imgs/placeholder.jpg">' } } } |