Sub topic 1
Why technicians script
Scripting is the practice of writing a short text file of commands that a computer runs in order. This chapter covers why support technicians do it, what it saves, and where it can go wrong. Later chapters cover the file types, syntax, and remote access tools in detail.
Prerequisites
This chapter assumes you can already do the following:
- Open the Windows command prompt and a Linux shell and run basic commands.
- Read Windows and Linux file paths, such as
C:\Users\Samand/home/sam. - Use basic networking terms: IP address, port, and firewall.
You do not need to write code yet. The examples here are for reading.
What a script is
A script is a plain text file that holds a list of commands. An interpreter reads the file and runs the commands one after another. The interpreter is a program such as cmd.exe, PowerShell, Bash, or Python. A script is not compiled ahead of time into a separate program. You can open it in any text editor and read exactly what it does.
Anything you can type at a command line, you can put in a script. The script adds three things on top of typing:
- Repeatability. The same commands run the same way every time.
- Logic. The script can make decisions (conditionals) and repeat steps (loops).
- Scale. One script can run on 5 computers or 500.
The problem scripts solve
A technician's day contains many small tasks that repeat. Examples include mapping a network drive for each new employee, clearing temporary files, or checking whether a service is running. Doing these by hand has three costs.
- Time. Ten clicks per machine across 200 machines is 2,000 clicks.
- Mistakes. People skip steps, mistype names, and forget which machines they finished.
- Inconsistency. Two technicians do the same job in two different ways, so machines end up configured differently.
Automation is the general term for letting software do a repeated task without a person performing each step. Scripting is the most common way a technician automates work.
A worked example
Suppose every new hire needs a shared drive mapped as Z:. By hand, you open File Explorer, choose Map network drive, pick a letter, type the path, and tick "Reconnect at sign-in." In a script, the same job is one command plus a check:
@echo off
REM Map a network drive and confirm it
net use Z: \\fileserver\shared /persistent:yes
if %ERRORLEVEL% EQU 0 (
echo Drive Z: mapped.
) else (
echo Mapping failed.
)Read it line by line:
@echo offstops the command prompt from printing each command before it runs.REMmarks a comment. The interpreter ignores that line, and it exists for human readers.net use Z: \\fileserver\shared /persistent:yesmaps the drive and keeps it after a restart.%ERRORLEVEL%holds the exit code of the last command. An exit code of0conventionally means success. Any other value means an error.- The
ifandelsepair prints a message that tells you which outcome happened.
The check at the end matters. A script that reports its own result is more useful than one that fails silently.
Scripting versus doing it by hand
Scripts are not always the right choice. The table compares the two approaches.
| Factor | Manual work | Script |
|---|---|---|
| Setup effort | None | Time to write and test |
| Cost per extra machine | Same each time | Close to zero |
| Consistency | Varies by person | Same every run |
| Record of what was done | Only if you write notes | The script itself documents the steps |
| Best for | One-off or unusual problems | Repeated or large-scale tasks |
A rough rule is that a task worth scripting is one you will do more than a few times, or one that must be done identically on many machines. For a single odd fault on one laptop, troubleshooting by hand is faster.
Where scripts run
Scripts are tied to a platform. The interpreter must exist on the machine that runs the file. The common pairings are:
| Platform | Typical script type | Interpreter |
|---|---|---|
| Windows | Batch file (`.bat`), PowerShell (`.ps1`) | Command prompt, PowerShell |
| Linux and macOS | Shell script (`.sh`) | Bash or another shell |
| Cross-platform | Python (`.py`) | Python interpreter |
| Windows (legacy) | VBScript (`.vbs`), JavaScript (`.js`) | Windows Script Host |
The next chapter covers these extensions in detail. For now, remember that choosing a language starts with asking what the target machine already has installed.
The same idea in three languages
The same task can be written in different languages. This PowerShell script lists the names of all stopped services:
# List stopped services
$stopped = Get-Service | Where-Object { $_.Status -eq 'Stopped' }
foreach ($svc in $stopped) {
Write-Output $svc.Name
}This Bash script copies text files from a user's Documents folder to a backup location:
#!/bin/bash
# Copy text files from Documents to a backup folder
src="$HOME/Documents"
dest="/mnt/backup"
for f in "$src"/*.txt; do
cp "$f" "$dest"
done
echo "Backup finished for user $USER"Both scripts use a variable, a loop, and a comment. The syntax differs, but the ideas are the same. Learning to see the ideas behind the syntax lets you read a script in a language you have never used. That skill is what the exam tests.
Where scripting fits in support work
Scripts show up in several areas of IT support:
- Provisioning: setting up new user accounts, mapping drives, and installing standard software.
- Maintenance: clearing caches, restarting services, and installing updates.
- Backups: copying files to another location on a schedule.
- Information gathering: collecting system details such as the IP address, installed software, or disk space for a report.
- Remote management: running the same script across many machines through a remote monitoring and management (RMM) tool. Later chapters cover RMM.
Each of these is covered in a later chapter. The point here is that scripting is a general tool, and the same skill supports every one of these jobs.
Risks to keep in mind
A script does exactly what it says, with the permissions of the account that runs it. That is the source of both its power and its risk.
- Malware. A script from an untrusted source can contain harmful commands. A downloaded
.bator.ps1file is code, not a document. - Unintended changes. A typo in a path can delete the wrong folder or change settings on every machine at once.
- Resource mishandling. A loop with no exit condition can use all the CPU, fill a disk, or lock files that other programs need.
Good habits reduce these risks. Read the script before running it. Add comments so the next person understands it. Keep a backup before any change that is hard to undo. Test on one machine before you run it on many.
How scripts connect to remote access
Scripts and remote access tools work together. Remote access lets you reach a machine that is not in front of you. A script lets you do something useful once you are there, or on many machines at once. The second half of this tutorial covers the remote tools: RDP, VNC, SSH, VPN, Microsoft Remote Assistance, RMM platforms, and third-party tools. Security matters for both halves, because a script run remotely with administrator rights has wide reach.
Key points
- A script is a text file of commands run by an interpreter.
- Scripts give repeatability, logic, and scale.
- The language you choose depends on the platform and what is installed.
- Scripts run with the permissions of the account that starts them, so read and test them first.
- Scripting and remote access are separate skills that you will often use together.
Exercise
A technician must set the same registry-free configuration on 150 Windows laptops, and the steps never change. Another technician has one laptop with an unusual Wi-Fi fault that appears only at certain times. For which job is a script the better choice, and why?
Show answer
A script is the better choice for the 150 laptops. The steps repeat and must be identical on every machine, so a script saves time, avoids mistakes, and keeps the configuration consistent. The single Wi-Fi fault is a one-off problem that needs investigation, so working on it by hand is faster than writing a script.
Exercise
In the batch example, what does %ERRORLEVEL% EQU 0 test, and why is that check useful?
Show answer
It tests whether the exit code of the previous command (net use) equals 0, which conventionally means success. The check is useful because the script can report whether the drive was really mapped, instead of failing silently.
Exercise
You receive a .ps1 file by email from an unknown sender and are asked to run it on a company server to "fix a problem." Name two risks and one safe step.
Show answer
Risks include malware hidden in the script and unintended changes to the server's settings or files, made with the permissions of the account that runs it. A safe step is to read the script first and, if it is still needed, test it on a non-production machine or virtual machine with a least-privilege account.