-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindDeadCode.ps1
60 lines (50 loc) · 1.27 KB
/
findDeadCode.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# this function recursively searches a target directory for a query string
# and writes any strings that are not found
# or that are only referenced by files whose names contain the query string
# to a target location
function queryBaseline($Query) {
$Result = Get-ChildItem -Recurse | Select-String -Pattern $Query -SimpleMatch | group path
If (-not($Result -eq $null))
{
If($Result.count -gt 0)
{
$externalRef = 0
$Display
$Result | ForEach {
$Display = $_.Values[0]
If(isExternalRef($Display) -eq 1){
$externalRef = $externalRef + 1
}
}
Write-Host "$externalRef external references to $Query found"
If($externalRef -eq 0){
Add-Content $Location "$Display"
}
}
else
{
Write-Host "no references to $Query found"
Add-Content $Location "$Display"
}
}
ElseIf ($Result -eq $null)
{
Write-Host "$Query not found"
Add-Content $Location "$Query"
}
}
function isExternalRef($Display){
$Return = 1
If($Display -Match $Query)
{
$Return = 0
}
return $Return
}
# this should point to the directory that you want to search
$Target = "c:\target\"
# this should point to where you want the output to go
$Location = "C:\output.txt"
Set-location $Target
queryBaseline "target.jsp"
Read-Host -Prompt 'Press any key'