4.8 Explain the basics of scripting.
📘CompTIA A+ Core 2 (220-1202)
A script is a file containing a series of commands that a computer can execute automatically. Scripts are widely used in IT to automate tasks, manage systems, or run programs without having to do everything manually. Different scripting languages use different file extensions.
Here are the most common script file types you need to know for the exam:
1. .bat (Batch File)
- What it is: A batch file is a script for Windows that contains a series of commands that run one after another in the Command Prompt.
- File extension:
.bator sometimes.cmd - How it’s used in IT:
- Automating repetitive tasks like deleting temporary files.
- Running multiple commands at once, e.g., mapping network drives for multiple users.
- Example commands inside a .bat file:
dir– lists files in a foldercopy– copies files from one folder to anotherecho– displays a message
Key point: Batch files are easy to write but mainly work on Windows systems.
2. .ps1 (PowerShell Script)
- What it is: A PowerShell script is used on Windows systems for more advanced tasks than batch files. It can work with files, users, and system settings.
- File extension:
.ps1 - How it’s used in IT:
- Automating system administration tasks like creating new user accounts in Active Directory.
- Managing Windows updates or system configurations.
- Why it’s important: PowerShell scripts are powerful because they can interact with almost every part of a Windows system.
Key point: Always run with proper permissions because .ps1 scripts can make major changes to the system.
3. .vbs (VBScript File)
- What it is: VBScript (Visual Basic Script) is a Windows scripting language. It is often used for automating tasks in Microsoft applications like Excel or for administrative tasks.
- File extension:
.vbs - How it’s used in IT:
- Automating Excel reports or reading data from files.
- Displaying messages or alerts to users automatically.
- Example command inside a .vbs file:
MsgBox "Backup complete!"– pops up a message box
Key point: VBScript is older but still used in some Windows environments.
4. .sh (Shell Script)
- What it is: A shell script is a script for Linux/Unix systems that runs in a shell like Bash.
- File extension:
.sh - How it’s used in IT:
- Automating server tasks, like starting/stopping services.
- Running maintenance scripts on Linux servers.
- Example commands inside a .sh file:
ls– lists files in a directorycp file1.txt file2.txt– copies a fileecho "Task complete"– displays a message
Key point: Shell scripts are essential for Linux/Unix administration and are executed in a terminal.
5. .js (JavaScript File)
- What it is: JavaScript is primarily a web scripting language used to make websites interactive.
- File extension:
.js - How it’s used in IT:
- Adding interactivity to websites, like forms and animations.
- Running scripts on the server side using Node.js (server-side JavaScript).
- Example commands inside a .js file:
console.log("System check complete");– logs messages for IT monitoring
Key point: JavaScript is widely used for web development, but can also be used for backend tasks with Node.js.
6. .py (Python File)
- What it is: Python is a high-level scripting language used for automation, data analysis, and general programming.
- File extension:
.py - How it’s used in IT:
- Writing scripts to automate tasks across multiple systems (e.g., moving files or monitoring system health).
- Parsing logs, processing data, or managing cloud resources.
- Example commands inside a .py file:
print("Backup finished")– prints a messageimport os– allows file and system management
Key point: Python is extremely versatile and works on Windows, Linux, and macOS.
Summary Table of Script File Types
| File Type | Platform | Purpose/Use in IT | Notes |
|---|---|---|---|
.bat | Windows | Automate command-line tasks | Simple, basic automation |
.ps1 | Windows | Advanced admin automation | Requires PowerShell |
.vbs | Windows | Microsoft app automation, messages | Older, limited now |
.sh | Linux/Unix | Server and system automation | Run in terminal/shell |
.js | Any (Web/Server) | Website interactivity, Node.js scripts | Mostly web-based |
.py | Cross-platform | Automation, data processing, general scripts | Very versatile |
✅ Exam Tip: For the CompTIA A+ exam, you should know the common file extensions, the platform they run on, and the basic use case for each. You don’t need to write complex scripts, just understand what each type does.
