-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetire-Plots.ps1
More file actions
68 lines (51 loc) · 1.71 KB
/
Copy pathRetire-Plots.ps1
File metadata and controls
68 lines (51 loc) · 1.71 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
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
61
62
63
64
65
66
67
68
param(
[Parameter(Mandatory=$true)]
[string]$DriveLetter
)
# Thresholds
$minFreeGB = 100
$maxFileKB = 42000000 # 42,000,000 KB
# Convert thresholds
$minFreeBytes = $minFreeGB * 1GB
$maxFileBytes = $maxFileKB * 1KB
# Normalize drive root
$drivePath = "${DriveLetter}:\"
# Get drive info
$drive = Get-PSDrive -Name $DriveLetter
if (-not $drive) {
Write-Host "Drive ${DriveLetter} not found."
exit 1
}
function Get-FreeSpace {
return (Get-PSDrive -Name $DriveLetter).Free
}
$free = Get-FreeSpace
Write-Host "Current free space on ${DriveLetter}: $([math]::Round($free/1GB,2)) GB"
# If already above threshold, exit
if ($free -ge $minFreeBytes) {
Write-Host "Drive already has at least $minFreeGB GB free. No action taken."
exit 0
}
Write-Host "Searching for .FPT files under $([math]::Round($maxFileBytes/1GB,2)) GB..."
# Correct Get-ChildItem usage
$fptFiles = Get-ChildItem -Path $drivePath -Recurse -Filter *.FPT -ErrorAction SilentlyContinue |
Where-Object { $_.Length -lt $maxFileBytes } |
Sort-Object Length -Descending
if ($fptFiles.Count -eq 0) {
Write-Host "No .FPT files under size limit found. Cannot free space."
exit 1
}
Write-Host "Found $($fptFiles.Count) candidate files."
foreach ($file in $fptFiles) {
Write-Host "Deleting $($file.FullName) ($([math]::Round($file.Length/1GB,2)) GB)"
Remove-Item $file.FullName -Force
# Recalculate free space
$free = Get-FreeSpace
Write-Host "Free space now: $([math]::Round($free/1GB,2)) GB"
if ($free -ge $minFreeBytes) {
Write-Host "Target reached: $([math]::Round($free/1GB,2)) GB free."
exit 0
}
}
Write-Host "All candidate files deleted but free space is still below $minFreeGB GB."
exit 1