2012-07-17 47 views
0

我正在尋找一些代碼來搜索日誌文件的註冊表內容。具體來說:事件日誌中的Powershell搜索註冊表內容

Get-ItemProperty -path hklm:\system\currentcontrolset\enum\usbstor\*\* | select PSChildName 

會列出序列號。對於每個序列號,我需要能夠搜索文本日誌文件以查看該項目何時出現。

這裏是我使用的是什麼現在:

Get-ItemProperty -path hklm:\system\currentcontrolset\enum\usbstor\*\* | select PSChildName | foreach-object {Get-Content C:\Windows\inf\setupapi.dev.log | select-string '$_.PSChildName' -context 1} 

PSChildName搜索不工作,我缺少什麼?

回答

0

我認爲它的原因|沒有通過$ _。PSChildName發送任何東西。所以,你可以使用1 2解決方案

解決方案1 ​​

Get-ItemProperty -path hklm:\system\currentcontrolset\enum\usbstor\*\* | select PSChildName | foreach-object {$P = $_.PSChildName ; Get-Content C:\Windows\inf\setupapi.dev.log | select-string $P -SimpleMatch -context 1} 

解決方案2

$KeyListArray = @() 
    Foreach($key in Get-ItemProperty -path hklm:\system\currentcontrolset\enum\usbstor\*\* | select PSChildName) 
    {$KeyListArray +($key)} 


foreach($PsChild in $KeyListArray) 
{Get-Content C:\Windows\inf\setupapi.dev.log | select-string -Pattern "$PsChild" -context 1} 
+0

大,該訣竅 – Nik 2012-07-20 02:55:22

+0

好樂於幫助,請你能標記爲answered.What解決方案將使用1或2 – justinf 2012-07-20 06:58:38