File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,8 +13,13 @@ param(
1313
1414pslist - t - accepteula - nobanner
1515
16- $absDir = Resolve-Path $Dir
17- " Finding handles in $absDir "
16+ if (Test-Path - Path $Dir ) {
17+ $absDir = Resolve-Path $Dir - ErrorAction Stop
18+ } else {
19+ Write-Output " Skipping: Directory $ ( $Dir ) does not exist, no file-handles can exist."
20+ exit 0
21+ }
22+ Write-Output " Finding handles in $absDir "
1823$OUT = $ (handle64 - accepteula - nobanner $absDir )
1924
2025$processMap = @ {}
@@ -31,18 +36,18 @@ ForEach ($line in $OUT -split "`r`n")
3136
3237if ($processMap.Count -eq 0 )
3338{
34- " No handles found."
39+ Write-Output " No handles found."
3540}
3641else
3742{
3843 $processMap | Format-Table
3944
40- " Whitelisted: $Whitelist "
45+ Write-Output " Whitelisted: $Whitelist "
4146 foreach ($ppid in $processMap.keys )
4247 {
4348 $imageName = $processMap .$ppid
4449 if (! $Whitelist.Contains ($imageName )){
45- " Killing $ppid "
50+ Write-Output " Killing $ppid "
4651 taskkill / f / t / pid $ppid
4752 }
4853 }
You can’t perform that action at this time.
0 commit comments