-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchAndDestroy.ps1
43 lines (40 loc) · 1.46 KB
/
SearchAndDestroy.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
[CmdletBinding()]
Param (
[Parameter(Mandatory=$false)] $drive = 'C:\Data\Movies',
[Parameter(Mandatory=$true)] $name
)
Write-Host "Here are the files that will be destroyed:" -ForegroundColor Yellow
$movieList = @(Get-ChildItem -Path $drive -Filter *$($name)* -Directory)
$movieList.ForEach({Write-Host $_.FullName -ForegroundColor Red})
Write-Host "Do you want to run in bulk mode or individual mode (type exit to exit)? B/I" -ForegroundColor Yellow
$bulk = Read-Host
if ($bulk.ToLower() -eq 'b') {
Write-Host "Confirm again if this list should be deleted (Y/N):" -ForegroundColor Yellow
$movieList.ForEach({Write-Host $_.FullName -ForegroundColor Red})
$del = Read-Host
if ($del.ToLower() -eq 'y') {
$movieList.ForEach({Remove-Item -Path $_.FullName -Recurse -Force})
}
else {
exit 0
}
} elseif ($bulk.ToLower() -eq 'i') {
foreach ($movie in $movieList) {
Write-Host $movie.FullName -ForegroundColor Red
Write-Host "Delete this folder? (Y/N)" -ForegroundColor Yellow
$confirm = Read-Host
if ($confirm.ToLower() -eq 'y') {
$folder = Get-Item $movie.FullName
Remove-Item -Path $folder -Recurse -Force
Write-Host "Deleted folder...moving on" -ForegroundColor Magenta
} else {
Write-Host "Skipping...moving on" -ForegroundColor DarkMagenta
continue
}
}
} elseif ($bulk.ToLower() -eq "exit") {
exit 0
}
else {
exit 0
}