切断特定单词后的所有内容 - Powershell

Cut off everything after a specific word - Powershell

我正在尝试使用 powershell 删除 html 文件中某个词后的所有内容,但失败需要帮助

$s = get-content "C:\Users\admin\Desktop\File\sheet003.html"

$pos = $s.IndexOf(">0<")
$leftPart = $s.Substring(0, $pos)
#$rightPart = $s.Substring($pos+1)

$leftPart

但出现以下错误:

Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero.
Parameter name: length"
At line:4 char:1
+ $leftPart = $s.Substring(0, $pos)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

使用:

 get-content "C:\temp\sheet003.html" -raw

因为否则你得到一个数组而不是字符串到 $s