$path = "Documents\hoge.txt"
$text = "てすと"
$file = @(Get-Content $path)

for($i = $file.count; $i -ge 0; $i--)
{
if($file[$i] -match "^\s*$")
{
continue
}

if($file[$i] -match ".*$($text).*")
{
$file[$i] = $text
} else {
$file[$i] += "`n" + $text
}

break
}

$file | Out-File $path

Powershell勉強中なんだけどこんな感じ?