# $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.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-file-deletelineinfile/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### 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

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

### Parameters

#### file (String)

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

#### text (String)

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

#### onlyfirstmatch (Boolean)

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

#### ignorecase (Boolean)

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

### Return value

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

### Example

**PowerShell**

```powershell
$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:

```powershell
$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:

```powershell
$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:

```powershell
$cs.File_DeleteLineInFile($ConfigFile, "DEBUG=true", $true, $false)
```

### Related functions

[$cs.File_AppendToFile](/capainstaller/powerpacks/cs-file-appendtofile/)
