Sorry for the delayed reply…it was a long weekend here in Canada.
You should probably do some of this work step by step either using a debugger (PowerShell comes with one) or interactively in the console so that you can see what is going on in each line of your script. For example, assuming your first file was \foo\c$\testext.txt, you could do this:
$contents = Get-Content \foo\c$\testext.txt`
Once you have the contents read in, verify the type and the contents meet your expectations.
Now that you see the contents, try to replace your text, see if that also meets your expectations, like this:
# Note, you can use replace on an array, and you don’t need to specify the replacement text if you are just removing it.
$newContents = $contents -replace ‘EXCLUDE.DIR “C:\Documents and Settings”’
If that is what you want written to the new file, then see if you can do that next:
Out-File -FilePath C:\testext2.txt -InputObject $newContents
Now, in writing this I changed a few things in your logic. First, I set it up to read the entire file and store it in an array. Then I applied replace to the array to remove the unwanted string (you can replace on an array and it will work on every item in the array). Then I added logic to write the new contents to a new file.
Give some of these things a try and let me know how it works out.