← HomeSeries
Software Through the Ages
EPISODE 35 · 1981 → today

Batch files to PowerShell: scripting Windows

Every computer user eventually types the same commands again and again: copy the day's data, rename files, clean old logs, back up a folder. A script — a text file of commands — lets the computer do it. On the PC that began with humble DOS batch files in 1981 and grew through REXX and Windows Script Host to PowerShell, with Python now the universal glue. This episode opens Season 7 on macros and automation.

1981
MS-DOS 1.0 runs .BAT batch files and AUTOEXEC.BAT
1979
IBM's REXX scripting language (later in OS/2)
1998
Windows Script Host: VBScript and JScript
2006
PowerShell 1.0 — commands that pass objects, not text
2018
PowerShell becomes open source and cross-platform
~2027
VBScript disabled by default on its way out of Windows

01The requirement: let the computer repeat the work

RequirementWhyWhat scripting offered
Start-up configurationDrivers, paths and settings had to be loaded at every bootCONFIG.SYS and AUTOEXEC.BAT
Repeat routine jobsCopying, renaming, cleaning and backing up by hand wastes time and invites mistakesBatch files and scripts
Run unattendedJobs should run at night or when data arrivesTask Scheduler, cron
Manage many computersOffices grew from five PCs to five thousandLogon scripts, VBScript, then PowerShell remoting
Glue programs togetherData must pass from a logger to analysis to a reportPipes, file handling, Python

02Fifty years of scripts

1960s–70s — Job control and the shell. Mainframes used job control language (JCL) to run batches of programs — hence "batch file". Unix shells (1971 onward; the Bourne shell 1979) made scripting a normal part of computing, and cron ran jobs on a timetable.
1979 — REXX. Mike Cowlishaw at IBM created REXX, a readable scripting language for mainframes. It became the scripting language of OS/2 (Episode 06) and the Amiga (ARexx).
1981 — DOS batch files. COMMAND.COM ran .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.
1989 — 4DOS. JP Software's replacement command processor added better variables, loops and command history; many power users switched.
1993 — CMD.EXE. Windows NT's command processor extended batch language with FOR /F, SET /A arithmetic and delayed expansion. The same CMD runs today.
1996–1998 — Windows Script Host. VBScript (1996) and JScript, run by Windows Script Host (Windows 98, 1998), could control Windows and Office through COM objects. Network administrators wrote logon scripts; virus writers wrote ILOVEYOU (Episode 32).
2002–2006 — Monad becomes PowerShell. Jeffrey Snover's "Monad Manifesto" (2002) proposed a shell whose commands pass .NET objects rather than text. PowerShell 1.0 shipped in November 2006; Windows 7 included version 2.0 with remoting.
2016–2020 — Open and cross-platform. PowerShell was open-sourced in 2016; PowerShell Core 6 (2018) and PowerShell 7 (2020) run on Windows, Linux and macOS. Windows Terminal (2019) and winget (2020) modernised the command line.
2023 → — VBScript retired. Microsoft deprecated VBScript in October 2023. In Windows 11 24H2 it became an optional feature, still on by default; around 2027 it is to be disabled by default, and later removed.

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
PowerShell also manages Windows itself: services, event logs, registry, Active Directory (Episode 34), Exchange and Microsoft 365. -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") -NoTypeInformation

Run 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, echo instead of del, 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

ToolWhereNotes
PowerShell 7github.com/PowerShell/PowerShellwinget install Microsoft.PowerShell (Windows PowerShell 5.1 is already built in)
Windows TerminalMicrosoft Storewinget install Microsoft.WindowsTerminal
Pythonpython.orgwinget install Python.Python.3.13
VS Code + PowerShell extensioncode.visualstudio.comEditing, debugging and running scripts

10Lessons for engineers

  1. Automate the second time, not the tenth. A ten-line script repays itself within a week of test-data handling.
  2. Prefer objects to text. PowerShell and Python survive changes in output format; text-parsing batch files do not.
  3. Log what the script did. An unattended job with no log is a mystery when it fails.
  4. Plan for retirement. VBScript is leaving Windows; move old .vbs scripts to PowerShell or Python now.

Sources & further reading

  1. Microsoft — VBScript deprecation: timelines and next steps (May 2024)
  2. Wikipedia — Batch file · REXX · Windows Script Host
  3. Wikipedia — PowerShell · Jeffrey Snover, Monad Manifesto, 2002
  4. Microsoft Learn — PowerShell documentation · robocopy reference