I'm new to PowerShell and trying to remove white space from a file. The file contains some values and has white spaces (indentation):

```
Hostname=hostname1
Server=server1
Directory=C:\Program Files\Test
Database=db1

```

I am trying to remove white space, but preserve the "directory" line as it contains a whitespace in the path `C:\Program Files\Test` and this will break the build. This is the code I have so far:

```
foreach ($Line in (Get-Content -Path C:\File.txt) | Where-Object {$_ -notcontains "Directory"}) {
    $line -replace " ", ""
    Set-Content -Path C:\File.txt
}

```

But this produces an empty file. What am I doing wrong?