$Driveinfo.maximum rapporteras inte,
Prova att vända på det hela som nedan, leta efter ledigt utrymme istället.
Alltså det får inte vara mindre än 20% ledigt, om det är mindre än 20% ledigt då startar raderingen.
(Tror det fungerar nedan det lilla jag testade.)
FET markerar det jag ändrade i ditt skript.
# Konfigurera variabler
$drive = "C" # Enhet att övervaka (t.ex. C:, D:)
$threshold = 20 # Procentsats som aktiverar filradering
$path = "C:\ContaCam\2024" # Mappen att rensa
$filter = "*.*" # Filtyp att ta bort (t.ex. *.tmp eller *.* för alla filer)
$daysOld = 5 # Filer äldre än detta antal dagar kommer att tas bort
# Kontrollera enhetens fyllnadsgrad
$driveInfo = Get-PSDrive -Name $drive
$currentUsage = ($driveInfo.Used / $driveInfo.Free) * 100
# Om fyllnadsgraden överskrider tröskelvärdet
if ($currentUsage -lt $threshold) {
Write-Output "Hårddisken har $([math]::Round($currentUsage, 2))% ledigt. Rensning startar."
# Hämta och ta bort filer äldre än $daysOld dagar
Get-ChildItem -Path $path -Filter $filter -Recurse | Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-$daysOld)
} | Remove-Item -Force -Recurse
Write-Output "Rensning klar."
} else {
Write-Output "Hårddisken har $([math]::Round($currentUsage, 2))% ledigt. Ingen åtgärd krävs."
}
Länken nedan ger en fingervisning och det finns ingen exakt siffra men klart värt att tänka på för maximal stabilitet.
"Solid-state drives
The free space recommendation for an SSD is higher than HDDs. The empty blocks on the solid-state drive used by the computer to write data. When all available space used, it takes longer for the programs to find partially empty blocks. An SSD will become slow and its write performance will decrease as it gets filled up. So, to avoid this issue, it is best to keep at least 25% free space. When the space in your SSD starts exhausting, it becomes difficult for the drive to write the new data to the partially filled blocks because that would delete the existing data. So, to write the data, the drive would need to read the value of the block into its cache. The SSD will then modify the value with the new data to write a file. All this will take a lot of time.
It is noteworthy here that the latest operating systems have the TRIM feature. Once you delete a file, this feature will automatically delete that file’s data from your SSD. The TRIM feature empties the block so that new data can written to the empty block. However, if you use the entire available space before deleting extra files, you may have several partially filled blocks.
The TRIM command doesn’t perform any cleanup and it can’t even consolidate the partially filled blocks into full blocks. So, make sure to avoid filling your SSD before deleting files because that would create partially filled blocks and SSD’s performance will degrade. Some SSD manufacturers reserve about 7% of their total flash storage which is unavailable to the user. The purpose of this “overprovisioning” is to prevent consumers from filling up their SSD. However, whether your SSD has this feature or not, make sure to avoid using more than 75% of your SSD’s capacity.
Read more: https://platinumdatarecovery.com/blog/fill-up-full-capacity © PlatinumDataRecovery.com"