Script types

2.6 Summarize scripting basics for server administration.

📘CompTIA Server+ (SK0-005) 


Scripting is essential for automating tasks in server administration. Scripts allow administrators to perform repetitive tasks quickly, manage systems consistently, and reduce errors. Different operating systems and environments use different scripting languages.

1. Bash Scripts

  • What it is:
    Bash (Bourne Again Shell) is a command-line scripting language used mainly in Linux and Unix servers.
  • Purpose:
    Automates system tasks, like creating users, managing files, monitoring system performance, and scheduling backups.
  • Characteristics:
    • Runs in the terminal (shell) of Linux/Unix systems.
    • Can execute multiple commands in sequence automatically.
    • Supports variables, loops, and conditional statements (if, while, for).
  • Example IT uses:
    • Automatically clean up log files older than 30 days.
    • Monitor CPU or disk usage and send an alert if thresholds are exceeded.
    • Deploy software updates across multiple Linux servers.

Example Bash Script:

#!/bin/bash
# This script checks disk usage and alerts if above 80%
THRESHOLD=80
USAGE=$(df / | grep / | awk '{print $5}' | sed 's/%//')
if [ $USAGE -gt $THRESHOLD ]; then
echo "Warning: Disk usage is above $THRESHOLD%" | mail -s "Disk Alert" admin@example.com
fi
  • This checks disk usage and emails the admin if usage is high.

2. Batch Scripts

  • What it is:
    Batch scripts (.bat or .cmd) are used in Windows environments. They are simple text files containing a series of commands executed by the Windows Command Prompt.
  • Purpose:
    Automates Windows system tasks like file management, running programs, and network tasks.
  • Characteristics:
    • Easy to write for simple tasks.
    • Limited compared to PowerShell but sufficient for basic automation.
    • Uses commands like copy, del, mkdir, and loops with for.
  • Example IT uses:
    • Map network drives for all users automatically at login.
    • Clean temporary files from servers every night.
    • Restart services automatically if they stop unexpectedly.

Example Batch Script:

@echo off
REM This script deletes all .tmp files in C:\Temp
del /Q C:\Temp\*.tmp
echo Temporary files deleted.
  • This clears temporary files to free disk space.

3. PowerShell Scripts

  • What it is:
    PowerShell (.ps1) is a Windows scripting language designed for advanced administration. Unlike batch scripts, it is object-based, not just text-based.
  • Purpose:
    Automates and manages Windows servers, Active Directory, and cloud services efficiently.
  • Characteristics:
    • Can access Windows system internals, services, registry, and event logs.
    • Supports loops, functions, conditional statements, and error handling.
    • Works well with remote servers using PowerShell remoting.
  • Example IT uses:
    • Create multiple user accounts in Active Directory at once.
    • Schedule server maintenance tasks, like backups or service restarts.
    • Gather detailed reports about server hardware, software, and network configuration.

Example PowerShell Script:

# This script lists all services that are stopped
Get-Service | Where-Object {$_.Status -eq "Stopped"} | Select-Object Name, Status
  • This retrieves all stopped services so an admin can restart critical ones.

4. Virtual Basic Script (VBS)

  • What it is:
    VBS (.vbs) is an older Windows scripting language based on Visual Basic. It is mostly used for automation on desktops or legacy servers.
  • Purpose:
    Automates tasks in Windows that batch scripts or PowerShell may not handle easily, such as interacting with applications or creating pop-up messages.
  • Characteristics:
    • Can interact with Windows GUI applications.
    • Often used for simple administrative tasks like file operations, logging, or message alerts.
    • Less commonly used today, replaced largely by PowerShell.
  • Example IT uses:
    • Display a message to users about system maintenance.
    • Automate file copying between folders.
    • Log server events to a text file for monitoring purposes.

Example VBS Script:

' This script displays a message box
MsgBox "Server maintenance will start at 10 PM", vbInformation, "Maintenance Notice"
  • Shows a notification to users about upcoming maintenance.

Key Points to Remember for the Exam

  1. Bash → Linux/Unix servers, terminal-based, great for system tasks and monitoring.
  2. Batch → Windows, simple command automation, basic file and service management.
  3. PowerShell → Windows, advanced, object-based, works with AD and remote servers.
  4. VBS → Windows, legacy scripting, GUI automation, and simple administrative tasks.

Exam Tip: Focus on which OS each script type is used for, what level of automation it provides, and typical IT scenarios rather than remembering long syntax. Being able to identify the best script type for a task is often tested.

Buy Me a Coffee