2010-01-21 22 views
1

我正在嘗試通過我們的Intranet的.htm文件進行搜索,以找出哪些網絡文件正在鏈接到網站的哪些頁面上。我想要做的是讓PowerShell檢查每個.htm並返回任何以「file:///」開頭並以雙引號結尾的字符串。例如:如何使用PowerShell的選擇字符串從.htm文件中提取文件名?

<td colspan="3"><a href="file:///X:/Name of Document.doc" style="text-decoration: none"> 

將返回:

file:///X:/Name of Document.doc 

至於PowerShell的命令,我一直用這個:

select-string -Path [Document Path] -Pattern '[Pattern]' -AllMatches | % { $_.Matches } | % { $_.Value } 

我遇到的唯一麻煩的是,我不能找出我應該使用的正則表達式來提取我正在查找的字符串。有任何想法嗎?

回答

4

這種模式應該工作:`文件:/// [^「] *」例如爲:

$str = @' 
<td colspan="3"> 
    <a href="file:///X:/Name of Document.doc" style="text-decoration: none"> 
'@ 
$str | select-string '(file:///[^"]*)' | %{$_.Matches[0].Value} 

file:///X:/Name of Document.doc 
+0

工作就像一個冠軍,謝謝! – 2010-01-21 16:51:05

相關問題