$cs.File_DeleteLineInFile
Description
Section titled “Description”Removes line(s) containing text from file. By default only the first matching line is removed, using a case-insensitive substring match; file must already exist.
Syntax
Section titled “Syntax”$cs.File_DeleteLineInFile(string file, string text, bool onlyfirstmatch = true, bool ignorecase = true)
Parameters
Section titled “Parameters”file (String)
Section titled “file (String)”Full path to the file to remove line(s) from. Throws an error if it does not exist.
text (String)
Section titled “text (String)”Text to search for within each line. Any line containing this text is a match.
onlyfirstmatch (Boolean)
Section titled “onlyfirstmatch (Boolean)”If $true (default), only the first matching line is removed. If $false, every matching line in the file is removed.
ignorecase (Boolean)
Section titled “ignorecase (Boolean)”If $true (default), the text match is case-insensitive. If $false, the match is case-sensitive.
Return value
Section titled “Return value”None. The number of removed lines is written to the CapaInstaller log, but is not returned to the caller.
Example
Section titled “Example”$cs.File_DeleteLineInFile("$env:windir\System32\Drivers\etc\hosts","127.0.0.1 assets.cloud.barco.com")To remove every line containing the text instead of just the first match:
$cs.File_DeleteLineInFile("$env:windir\System32\Drivers\etc\hosts","assets.cloud.barco.com", $false)During uninstall, remove a specific setting the install added to an application’s config file:
$ConfigFile = "$env:ProgramData\Contoso\App\app.conf"$cs.File_DeleteLineInFile($ConfigFile, "UpdateChannel=Stable")Use ignorecase=$false when the text match must be case-sensitive, for example to avoid matching an unrelated line that only differs in casing:
$cs.File_DeleteLineInFile($ConfigFile, "DEBUG=true", $true, $false)