-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGet-SelectedRules.ps1
44 lines (35 loc) · 1.55 KB
/
Get-SelectedRules.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Given a csv of selected ID's for sigma rules, copy those rules from a sigma-master repo download into another folder for further processing.
param (
[string]$Rules,
[string]$SelectedIDs
)
# Set variables
$csvPath = "C:\path\to\selected_ids.csv"
$sourceRoot = "C:\path\to\sigma-master\rules"
$destinationRoot = "C:\path-to\sigma-master\select_rules"
# Import strings from CSV
$stringsToFind = Import-Csv $csvPath | Select-Object -ExpandProperty *
# Get all files recursively
$files = Get-ChildItem $sourceRoot -Recurse | Where-Object { !$_.PSIsContainer }
# Loop through each file
foreach ($file in $files) {
# Read the content of the file
$content = Get-Content $file.FullName
# Check if any of the strings exist in the file content
foreach ($string in $stringsToFind) {
if ($content -match $string) {
# Build destination path, maintaining folder structure
$relativePath = $file.FullName.Substring($sourceRoot.Length).TrimStart("\")
$destinationPath = Join-Path $destinationRoot $relativePath
$destinationDir = Split-Path $destinationPath
# Create the destination directory if it doesn't exist
if (!(Test-Path -Path $destinationDir)) {
New-Item -ItemType Directory -Force -Path $destinationDir
}
# Copy the file
Copy-Item $file.FullName -Destination $destinationPath
# Break inner loop once a match is found and file is copied
break
}
}
}