01The requirement: let the computer repeat the work
| Requirement | Why | What scripting offered |
|---|---|---|
| Start-up configuration | Drivers, paths and settings had to be loaded at every boot | CONFIG.SYS and AUTOEXEC.BAT |
| Repeat routine jobs | Copying, renaming, cleaning and backing up by hand wastes time and invites mistakes | Batch files and scripts |
| Run unattended | Jobs should run at night or when data arrives | Task Scheduler, cron |
| Manage many computers | Offices grew from five PCs to five thousand | Logon scripts, VBScript, then PowerShell remoting |
| Glue programs together | Data must pass from a logger to analysis to a report | Pipes, file handling, Python |
02Fifty years of scripts
.BAT files: lists of commands with IF, GOTO, FOR and %1 parameters. AUTOEXEC.BAT ran at every start-up — the first thing many PC users ever edited. MS-DOS 3.3 (1987) added CALL and @ECHO OFF.FOR /F, SET /A arithmetic and delayed expansion. The same CMD runs today.03Try it: one job, three languages
Pick a routine job. The demo shows the same task as a batch file, a PowerShell script and a Python script, and runs it on a sample test-data folder. Notice how PowerShell and Python work with file objects (name, size, date) while batch mostly juggles text.
Dry run on a sample folder (today = 2026-11-15)
04Why PowerShell is different
Text pipelines (batch, Unix shells)
Each command prints text; the next command must cut that text apart to find the size or date column. Change the output format or the language of Windows, and scripts break.
dir /s *.log | find "11/2026"
Object pipelines (PowerShell)
Each command passes objects with named properties. The next command asks for .Length or .LastWriteTime directly. Commands are named Verb-Noun: Get-ChildItem, Sort-Object, Export-Csv.
Get-ChildItem -Recurse *.log | Where-Object LastWriteTime -gt (Get-Date).AddDays(-7) | Export-Csv recent_logs.csv
-WhatIf on most commands shows what would happen without doing it — use it on every delete.05Running scripts on a schedule
Windows 95's Plus! pack introduced System Agent; Windows 98 renamed it Task Scheduler, which today can start scripts at a time, at log-on, at start-up or on an event. Unix systems use cron. The command-line schtasks creates a task in one line:
schtasks /create /tn "Clean old logs" /sc daily /st 18:00 ^ /tr "powershell -NoProfile -ExecutionPolicy Bypass -File D:\Scripts\clean_logs.ps1"
The ^ continues the line in CMD. Run the task once by hand (schtasks /run /tn "Clean old logs") before trusting it.
06Ready-to-use examples
Copy, save with the extension shown, change the folder paths, and test on a copy of your data first.
A. Daily test-data copy with log (batch, daily_copy.bat)
@echo off rem Copy new and changed test files from the logger PC share to the archive. rem ROBOCOPY only copies what has changed and writes a log. set SRC=\\LOGGER-PC\Data set DST=D:\Archive\Data robocopy "%SRC%" "%DST%" *.csv *.dxd /E /XO /R:2 /W:5 /LOG+:"%DST%\copy_log.txt" /NP if %ERRORLEVEL% GEQ 8 (echo Copy FAILED - check the log & exit /b 1) echo Copy finished OK.
ROBOCOPY exit codes below 8 mean success (0 = nothing new, 1 = files copied).
B. Summary of today's CSV files (PowerShell, csv_summary.ps1)
# For each CSV written today, report the number of rows and the
# maximum of a chosen column, then save the summary as a new CSV.
param(
[string]$Folder = 'D:\Archive\Data',
[string]$Column = 'Oil_Temp_C'
)
$today = (Get-Date).Date
Get-ChildItem $Folder -Filter *.csv -File |
Where-Object LastWriteTime -ge $today |
ForEach-Object {
$rows = Import-Csv $_.FullName
[pscustomobject]@{
File = $_.Name
Rows = $rows.Count
Max = ($rows | Measure-Object -Property $Column -Maximum).Maximum
}
} |
Export-Csv (Join-Path $Folder "summary_$(Get-Date -Format yyyy-MM-dd).csv") -NoTypeInformationRun with .\csv_summary.ps1 -Column Vib_RMS. If scripts are blocked, allow your own with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.
C. Watch a folder and process new files (Python, watch_folder.py)
"""Check a folder every 30 s; when a new CSV appears, print its size and
row count, then move it to a 'done' sub-folder. Standard library only."""
import csv, shutil, time
from pathlib import Path
INBOX = Path(r"D:\Archive\Inbox")
DONE = INBOX / "done"
DONE.mkdir(exist_ok=True)
while True:
for f in sorted(INBOX.glob("*.csv")):
try:
with f.open(newline="") as fh:
rows = sum(1 for _ in csv.reader(fh)) - 1 # minus header
except PermissionError:
continue # still being written; try next time
print(f"{f.name}: {f.stat().st_size/1e6:.1f} MB, {rows} rows")
shutil.move(str(f), DONE / f.name)
time.sleep(30)07Script security
- Scripts are a favourite malware vehicle. VBScript, JScript and PowerShell attachments are blocked by most mail systems; never run a script you did not write or check.
- PowerShell execution policy (Restricted, RemoteSigned, AllSigned) prevents accidental running of downloaded scripts; it is a safety catch, not a security boundary.
- Test destructive commands with
-WhatIf,echoinstead ofdel, or on a copy of the folder. - Keep scripts in Git (Episode 16) with comments and a header block saying what, why and who.
08Version explorer
Blue chips: DOS and CMD batch. Amber chips: scripting languages and PowerShell.
09Getting the tools
| Tool | Where | Notes |
|---|---|---|
| PowerShell 7 | github.com/PowerShell/PowerShell | winget install Microsoft.PowerShell (Windows PowerShell 5.1 is already built in) |
| Windows Terminal | Microsoft Store | winget install Microsoft.WindowsTerminal |
| Python | python.org | winget install Python.Python.3.13 |
| VS Code + PowerShell extension | code.visualstudio.com | Editing, debugging and running scripts |
10Lessons for engineers
- Automate the second time, not the tenth. A ten-line script repays itself within a week of test-data handling.
- Prefer objects to text. PowerShell and Python survive changes in output format; text-parsing batch files do not.
- Log what the script did. An unattended job with no log is a mystery when it fails.
- Plan for retirement. VBScript is leaving Windows; move old .vbs scripts to PowerShell or Python now.
Sources & further reading
- Microsoft — VBScript deprecation: timelines and next steps (May 2024)
- Wikipedia — Batch file · REXX · Windows Script Host
- Wikipedia — PowerShell · Jeffrey Snover, Monad Manifesto, 2002
- Microsoft Learn — PowerShell documentation · robocopy reference