I've been through so many posts today that offer Powershell examples of how to remove entire lines from a file by using line numbers. Unfortunately none of them do quite what I need, or they have some 'but' type clauses in them.
The closest example I found uses the -remove method. This managed to do the job, until I noticed that not all lines that I was trying to remove, were removed. After some more research I found that -remove is reliant on Regex and Regex does not like certain special characters which happen to be in some of the lines I wish to delete/remove.
The example I'm using is not my own work. user2233949 made it (cheers buddy) I found it very simple though, so I made it into a Function:
Function DeleteLineFromFile ($Path, $File, $LineNumber){
$Contents = Get-Content $Path\$File
$Contents -replace $Contents[$LineNumber -1],"" | Set-Content $Path\$File
}
A great example I reckon. Only regex won't work with the special chars.
The goal is this: To make a function that doesn't care about what is in the line. I wan't to feed it a path, file and line, then have the function delete that line and save the file.