Skip to content

$cs.File_DeleteLineInFile

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.

$cs.File_DeleteLineInFile(string file, string text, bool onlyfirstmatch = true, bool ignorecase = true)

Full path to the file to remove line(s) from. Throws an error if it does not exist.

Text to search for within each line. Any line containing this text is a match.

If $true (default), only the first matching line is removed. If $false, every matching line in the file is removed.

If $true (default), the text match is case-insensitive. If $false, the match is case-sensitive.

None. The number of removed lines is written to the CapaInstaller log, but is not returned to the caller.

Terminal window
$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:

Terminal window
$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:

Terminal window
$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:

Terminal window
$cs.File_DeleteLineInFile($ConfigFile, "DEBUG=true", $true, $false)

$cs.File_AppendToFile