Номер строки, возвращаемый Select-String начинает отсчет с 1
.Индексы массива отсчитываются от 0
, поэтому вы должны учитывать это.
Это должно работать:
$chanName = "Das Erste HD"
$newRtsp = "the new content for the line"
# Getting the file
$inFile = Get-Content "iptv.m3u"
# Linenumber where a specific channel name $chanName perhaps exists?
# SimpleMatch is an optional parameter and specifies that
# the string in the pattern is not interpreted as a regular expression.
$line = ($inFile | Select-String "tvg-name=`"$chanName`"" -SimpleMatch).LineNumber #`# dummy comment to fix code highlighting for SO
# $line will be $null if Select-String did not find the string to look for
if ($line) {
# Use actual Linenumber minus 1 as Index, to override the following line
$inFile[$line - 1] = $newRtsp
# Write back to file
$inFile | Set-Content "iptv.m3u"
}