# Prompt the user to enter a drive letter for compression $drive = Read-Host "Please enter a drive letter for compression (e.g. C, D, E, F, etc.)" # Validate the drive letter input if ($drive -match "^[A-Z]$") { # Append a colon to the drive letter $drive = $drive + ":" } else { # Display an error message and exit the script Write-Error "Invalid drive letter. Please enter a single uppercase letter from A to Z." Exit } # Define the file types to exclude from compression $exclude = @("*.zip", "*.mp4", "*.mp3", "*.flv", "*.jpg", "*.png", "*.gif", "*.pdf", "*.rar", "*.7z", "*.tar", "*.gz", "*.wav", "*.aac", "*.ogg", "*.mkv", "*.avi", "*.docx", "*.xlsx", "*.pptx", "*.ttf", "*.otf", "*.woff") # Get all the files and folders on the drive $items = Get-ChildItem -Path $drive -Recurse # Loop through each item and check if it is compressible foreach ($item in $items) { # Skip the item if it is a directory or a symbolic link if ($item.PSIsContainer -or $item.LinkType) { continue } # Skip the item if it matches any of the excluded file types $skip = $false foreach ($ext in $exclude) { if ($item.Name -like $ext) { $skip = $true break } } if ($skip) { continue } # Compress the item using compact.exe with the /C, /I, /EXE:lzx and /EXCLUDE:exclude.txt options compact /C /I /EXE:lzx /EXCLUDE:exclude.txt $item.FullName }