-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathFindKeys.ps1
More file actions
24 lines (19 loc) · 963 Bytes
/
FindKeys.ps1
File metadata and controls
24 lines (19 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# to run this program, you have to have the windows utility PsExec.exe in this folder
# https://learn.microsoft.com/en-us/sysinternals/downloads/psexec
# Define variables
$folderPath = "C:\\ProgramData\\Microsoft\\Crypto\\RSA\\MachineKeys" # Replace with the folder you want to scan
$searchString = "\\ProgramData\\IoT Gateway\\"
# Create the PowerShell command to search for the string in files
$localCommand = "
Write-Output 'Starting search in folder: $folderPath'
Get-ChildItem $folderPath |
Foreach-Object {
`$content = Get-Content `$_.FullName
if (`$content -Match '$searchString') {
Write-Output `$_.FullName
#Remove-Item -Path `$_.FullName -Force # BE WARY OF UNCOMMENTING THIS LINE, IF SOMETHING GOES WRONG, IT COULD POTENTIALY DELETE IMPORTANT FILES. PLEASE BACKUP BEFORE YOU RUN.
}
}
"
# Run PsExec with -s (SYSTEM) to execute the command as SYSTEM
& ".\PsExec.exe" -s powershell.exe -NoProfile -Command $localCommand