# Define size threshold in MB and archive location
$sizeThresholdMB = 500
$archivePath = "C:\Archives"
# Create archive directory if it doesn't exist
if (!(Test-Path -Path $archivePath)) {
New-Item -ItemType Directory -Path $archivePath
}
# Find large files and move them to archive
Get-ChildItem -Path "C:\" -Recurse -File | Where-Object { $_.Length -gt ($sizeThresholdMB * 1MB) } | ForEach-Object {
Write-Output "Archiving file: $($_.FullName)"
Move-Item -Path $_.FullName -Destination $archivePath -Force
}
• Explanation: This script scans the C: drive for files larger than the specified size and moves them to an archive directory.