0

サーバー上のすべての共有で のワイルドカードを検索する PowerShell スクリプトを探しています*_HELP_instructions*。検索するファイルの例は、12_HELP_INSTRUCTIONS.txtまたは22_HELP_INSTRUCTIONS.html.

これまでのところ、C:\ の内容を検索する以下のスクリプトがありますが、代わりにサーバー共有を検索するようにセットアップできるスクリプトが必要です。

$FilesToSearch = Get-ChildItem "C:\*" -Recurse -ErrorAction SilentlyContinue |
                 where {$_.Name -like "*_HELP_instructions*"}

if ($FilesToSearch -ne $null) {
    Write-Host "System Infected!" 
    exit 2015
} else {
    Write-Host "System Not Infected!" 
    exit 0
}
4

3 に答える 3

0

フィードバックをお寄せいただきありがとうございます。すべてのコメントを考慮に入れると、最終的なコードは次のようになりました。

$exclude = 'Remote Admin', 'Remote IPC', 'Default share'
$shared  = Get-WmiObject Win32_Share |
       Where-Object { $exclude -notcontains $_.Description } |
       Select-Object -Expand Path

$FilesToSearch = Get-ChildItem $shared -Filter '*_HELP_instructions*' -Recurse -ErrorAction SilentlyContinue

If($FilesToSearch -ne $null) 

{
Write-Host "System Infected!" 
exit 2015
}

else 

{
Write-Host "System Clear!" 
exit 0
}
于 2016-12-13T16:26:42.410 に答える
0

a を使用してForEach Loop、検索が必要なすべてのパスをループできます。

$paths = Get-Content C:\Temp\Pathlist.txt

Foreach($path in $paths){
   $Filestosearch = Get-ChildItem $path -Recurse -ErrorAction SiltenlyContinue| where {$_.Name -like "*_HELP_instructions*"}
   If($FilesToSearch -ne $null) {
      Write-Host "System Infected!" 
   $Filestosearch | Export-Csv c:\Temp\Result.csv -NoTypeInformation -Append
   } else {
      Write-Host "System Not Infected!" 
      }
}

$pathこれは、ファイル内のそれぞれをループしC:\Temp\PathList.txtます。(例:C:\*または\\ServerName\MyShare\*)

次に、出力を にプッシュしますC:\Temp\Result.csv。システムが感染している場合。

txt ファイルに入れるパスの数によっては、実行に時間がかかります。しかし、それはあなたが求めているものを達成します!

お役に立てれば!

于 2016-12-13T12:30:13.063 に答える