-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch-passwords
More file actions
35 lines (27 loc) · 1.17 KB
/
search-passwords
File metadata and controls
35 lines (27 loc) · 1.17 KB
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
# Import the required modules
Import-Module PSWorkflow
Import-Module PSWorkflowUtility
# Prompt the user for the file location
$path = Read-Host "Enter the file location (e.g. C:\Users\Username\Documents)"
# Define the regular expression
$regex = '(?i)(p(as{2}w(or)?d|sk|w(or)?d?))\"{0,1}\s*?[:=>]'
# Create a workflow to search the files
Workflow Search-Files {
# Get a list of files in the specified location
$files = Get-ChildItem -Path $path -Recurse | Where-Object { -not $_.PSIsContainer }
# Search each file using the regular expression
foreach ($file in $files) {
# Read the contents of the file
$contents = Get-Content -Path $file.FullName
# Search the contents of the file using the regular expression
$matches = Select-String -InputObject $contents -Pattern $regex -AllMatches
# Print the matches
if ($matches) {
Write-Output "Matches found in the file $($file.FullName):"
Write-Output $matches.Matches | Select-Object -Property Value
}
}
}
# Start the workflow
Search-Files
# Stop-Workflow -InstanceId (Get-WorkflowInstance | Where-Object { $_.Name -eq 'Search-Files' }).InstanceId