コンテンツへスキップ

param(
    [parameter(mandatory=$true)][string]$filename
)

#$filename = "E:\my-document\powershell+word\テスト.docx"

$objWord = New-Object -Com Word.Application
$objWord.Visible = $false
$objDocument = $objWord.Documents.Open($filename)
$paras = $objDocument.Paragraphs

$pattern = "\[.*\]:.*\[.*\]"

foreach ($para in $paras) 
{ 
    #Write-Output $para.Range.Text
    $line = $para.Range.Text
    $line = $line.trim()
    if ($line -match $pattern) {
        write-output "Patternを含む=[" + $line + "]"
    } else {
        write-output "Pattern含まない=[" + $line + "]"
    }
}