Powershell-Batch-Scripts/Windows DVR/WindowsDVRCleanup.ps1

19 lines
672 B
PowerShell
Raw Normal View History

2024-10-21 06:50:02 +00:00
$envFilePath = ".\.env"
if (Test-Path $envFilePath) {
Get-Content $envFilePath | ForEach-Object {
if ($_ -match "^(.*?)=(.*)$") {
$name = $matches[1]
$value = $matches[2]
[System.Environment]::SetEnvironmentVariable($name, $value)
}
}
} else {
Write-Output ".env file not found"
exit
}
2024-10-21 06:50:02 +00:00
$maxAge = -([System.Environment]::GetEnvironmentVariable("MAX_AGE"))
$outputPath = [System.Environment]::GetEnvironmentVariable("OUTPUT_PATH")
# Get files older than MAX_AGE hours and delete them
Get-ChildItem -Path $outputPath -File | Where-Object { $_.LastWriteTime -lt (Get-Date).AddHours($maxAge) } | Remove-Item