EIEIOTECHNOVATION
← Training programmes

EIEIO / AUTOMATION & EMERGING TECHNOLOGY

Batch Scripting

Course outline

3 days

Duration

Batch Scripting

3 days

Overview

Batch programming, also known as batch scripting, refers to writing scripts in a plain text format to execute commands sequentially in a command-line interpreter. The most common environment for batch scripting is the Windows operating system, where these scripts are typically saved with a .bat or .cmd file extension. Batch programming has been a fundamental tool for system administrators, IT professionals, and power users for decades, enabling them to automate tasks, manage files, and control system operations efficiently.

This course will cover the fundamental concepts, explore advanced techniques, and apply the skills to solve real-world problems through hands-on activities.

Objectives

  • Grasp the fundamentals of batch scripting, including syntax, basic commands, and file operations.
  • Explore advanced scripting concepts such as flow control, functions, error handling, and network scripting.
  • Develop and deploy scripts to automate routine tasks, enhance productivity, and manage network operations.
  • Learn best practices for writing maintainable, secure, and efficient scripts.
  • Understand how to integrate batch scripts with other scripting languages and Windows utilities.

Target Audience

IT Professionals, System Administrators or Developers looking to automate repetitive tasks and manage systems more efficiently.

Prerequisite

Basic knowledge of Operating System, Networking and Simple Command Line interface is required.

Day 1: Fundamentals of Batch Scripting

Introduction to Batch Programming

  • History and evolution of batch scripting
  • Overview of the Windows Command Line Interface (CLI)
  • Batch script file structure and syntax
  • Introduction to command prompt
  • Creating and running a simple batch file

Basic Commands and Syntax

  • Basic commands: echo, cls, pause, rem
  • File operations: copy, del, rename, move
  • Directory operations: mkdir, rmdir, cd, dir
  • Hands-on exercises with basic commands
  • Creating a batch script to automate file organization

Variables and User Input

  • Using variables: set, set /p
  • Reading user input and setting environment variables
  • Working with command-line arguments (%1, %2, etc.)
  • Writing a script that takes user input to perform file operations
  • Creating scripts that use command-line arguments

Flow Control and Logic

  • Conditional statements: if, else, if exist, if not exist
  • Looping constructs: for, for /f, for /l
  • Error checking with errorlevel
  • Developing scripts with decision-making capabilities
  • Writing loops to automate repetitive tasks
  • Example scripts using flow control
  • Exercises on conditional logic

Practical Batch Scripting (Day 1)

  • Create a batch script to back up a directory
  • Write a script that takes multiple command-line arguments and processes files accordingly

Day 2: Advanced Batch Scripting Techniques

Functions and Modular Programming

  • Defining and calling functions in batch files
  • Reusability and modular script design
  • Creating batch functions
  • Modularizing a script for better maintainability
  • Examples of functions in batch scripts
  • Templates for modular scripts

Advanced Command Usage

  • Advanced for loops and text parsing
  • Using find and findstr for searching files
  • File and text processing with more, type, sort
  • Writing scripts to process log files
  • Searching for specific text patterns in files
  • Advanced command reference
  • Sample text processing scripts

Error Handling and Debugging

  • Detecting and handling errors: try, catch equivalent in batch
  • Using goto and exit for error handling
  • Debugging techniques and tools
  • Debugging a faulty script
  • Adding error handling to an existing script
  • Error handling techniques document
  • Scripts with intentional errors for debugging practice

Integrating Batch Scripts with Windows Utilities

  • Interfacing with Windows Task Scheduler
  • Utilizing schtasks, tasklist, taskkill
  • Automating system tasks with batch scripts
  • Scheduling a batch script with Task Scheduler
  • Creating scripts for system maintenance tasks
  • Task Scheduler documentation
  • Sample scripts for task automation

Practical Batch Scripting Project (Day 2)

  • Develop a batch script that automates a multi-step process (e.g., backup, processing, cleanup)
  • Implement error handling and logging

Day 3 : Networking, Security and Best PracticeNetwork Batch Scripting

  • Networking commands: ping, ipconfig, netstat
  • File sharing and network drives: net use, net share
  • Accessing remote machines: psExec, net view, net session
  • Writing scripts to check network connectivity and troubleshoot issues
  • Creating batch scripts for mapping network drives and sharing folders
  • Networking command reference
  • Example scripts for network operations

Scripting Best Practices

  • Best practices for writing maintainable scripts
  • Documentation and commenting
  • Version control and script management
  • Refactoring a script for readability
  • Adding comprehensive comments and documentation

Security Considerations in Batch Scripting

  • Understanding security risks in batch scripting
  • Implementing secure scripting practices
  • Handling sensitive information securely
  • Analyzing a script for security vulnerabilities
  • Writing scripts that handle sensitive data securely
  • Security guidelines for batch scripts
  • Case studies of script vulnerabilities

Integration with Other Scripting Languages

  • Calling PowerShell scripts from batch
  • Integrating with Python and other scripting languages
  • Using batch scripts to launch other applications
  • Creating a hybrid batch and PowerShell script
  • Launching a Python script from a batch file
  • Cross-language scripting examples
  • Sample hybrid scripts

Networking project

  • Network Connectivity and Resource Monitoring
  • Automated Backup of Network Shares

Programme scope, delivery arrangements and suitability are confirmed during enquiry.