Renaming dozens of files, sorting your Downloads folder, cleaning temporary files: these jobs are tedious, but a small script can do them in seconds. A script is just a text file containing commands that your computer runs in order. You do not need to be a programmer, and you can start with a few lines.
Why scripts are worth learning
- They save time on repetitive tasks and remove human error.
- They run the same way every time, so results are predictable.
- They can be scheduled to run automatically.
- They are small, free and built into your operating system.
Safety first
Scripts can delete or change files, so be careful. Always follow these rules:
- Never run a script you do not understand, especially one copied from a stranger.
- Back up important files before you test anything.
- Test on a copy of a folder first.
- Use the preview or
-WhatIfoption wherever it is available.
Read our disclaimer as well: you use all scripts at your own risk.
Which tool should you use?
On Windows, you can use batch files (.bat), which are simple and old, or PowerShell (.ps1), which is more powerful and the modern choice. On macOS and Linux, shell scripts (.sh) written for Bash or Zsh do the same job. The examples below use PowerShell on Windows.
Example 1: List the biggest files in a folder
This finds the ten largest files in your Downloads folder, which helps you decide what to delete. It makes no changes to your files.
Get-ChildItem "$env:USERPROFILE\Downloads" -File -Recurse |
Sort-Object Length -Descending |
Select-Object -First 10 Name, @{n='SizeMB';e={[math]::Round($_.Length/1MB,1)}}
Example 2: Sort downloads into folders by file type
This moves files into Images, Documents and Archives folders. Run it first with -WhatIf to preview what would happen.
$src = "$env:USERPROFILE\Downloads"
$map = @{
Images = '.jpg','.jpeg','.png','.gif','.webp'
Documents = '.pdf','.docx','.xlsx','.txt'
Archives = '.zip','.rar','.7z'
}
foreach ($folder in $map.Keys) {
$dest = Join-Path $src $folder
New-Item -ItemType Directory -Path $dest -Force | Out-Null
Get-ChildItem $src -File | Where-Object { $map[$folder] -contains $_.Extension.ToLower() } |
Move-Item -Destination $dest -WhatIf
}
When the preview looks correct, remove -WhatIf and run it again.
Example 3: Batch rename files with a prefix
Get-ChildItem "C:\Photos\Trip" -Filter *.jpg |
Rename-Item -NewName { "Trip2026_" + $_.Name } -WhatIf
How to run a PowerShell script
- Open Notepad, paste the script and save it with a name ending in
.ps1, for examplesort-downloads.ps1. - Right-click the Start button and open Terminal or PowerShell.
- Run
powershell -ExecutionPolicy Bypass -File "C:\path\to\sort-downloads.ps1"to run it for this one time without changing the system policy.
Run scripts automatically
On Windows, Task Scheduler can run a script at a set time, such as every Sunday evening. Create a basic task, choose a schedule and set the action to start PowerShell with the script as an argument. On macOS and Linux, use cron or launchd.
Other no-code automation options
- Browser extensions and bookmarklets for repetitive web tasks
- Power Automate on Windows and Shortcuts on macOS and iPhone for visual automation
- Text expanders that turn short abbreviations into full phrases or email replies
Learn more step by step
- Start with the built-in help:
Get-Help Move-Item -Examples - Change one small thing at a time and test again
- Keep a folder of your own working scripts with comments explaining what each does
Final thoughts
Automation is a skill that grows slowly. Start with a small, safe script such as listing large files, then try the sorting example and adjust it to your own folders. Soon you will spot repetitive tasks everywhere and know how to hand them to your computer.