Catalog / Windows Scripting Cheatsheet
Windows Scripting Cheatsheet
A quick reference guide for Windows scripting using PowerShell and Batch scripting, covering essential commands, syntax, and automation techniques.
PowerShell Basics
Core Commands (Cmdlets)
|
Lists all available PowerShell commands (cmdlets). |
|
Displays help information for a specific command. |
|
Configures the PowerShell execution policy (e.g., |
|
Retrieves information about running processes. |
|
Stops a running process (e.g., |
|
Retrieves information about Windows services. |
|
Starts a Windows service. |
|
Stops a Windows service. |
|
Restarts a Windows service. |
Variables and Operators
|
Indicates a variable (e.g., |
|
Assignment operator (e.g., |
|
Equality, inequality, greater than, and less than operators. |
|
Logical AND, OR, and NOT operators. |
|
Arithmetic operators (addition, subtraction, multiplication, division). |
|
Shorthand for incrementing/decrementing the value of a variable. |
Basic Syntax & Structures
|
|
|
|
|
PowerShell Advanced
Working with Objects
|
Displays the properties and methods of an object. |
|
Selects specific properties of an object (e.g., |
|
Filters objects based on a condition (e.g., |
|
Performs an action on each object in a collection (e.g., |
|
Exports objects to a CSV file (e.g., |
|
Imports objects from a CSV file (e.g., |
Modules and Script Execution
|
Imports a PowerShell module (e.g., |
|
Lists imported modules. |
|
Executes a PowerShell script in the current scope. |
|
Executes a PowerShell script in a new scope. |
|
Executes a PowerShell script. |
|
Publishes a module to a repository. |
Error Handling
|
|
|
Batch Scripting Basics
Basic Commands
|
Displays text on the console. |
|
Turns command echoing off (usually at the beginning of the script). |
|
Pauses script execution until a key is pressed. |
|
Clears the console screen. |
|
Sets the title of the console window. |
|
Exits the script. |
|
Comment a line (rem is compatible with older versions). |
Variables and Operators
|
Sets a variable (e.g., |
|
Accesses a variable’s value (e.g., |
|
Equality, not equal, greater than, and less than operators (string comparison). |
|
Conditional statement. |
|
For loop (e.g., |
|
Jumps to a labeled section of the script. |
File and Directory Operations
|
Lists files and directories in the current directory. |
|
Changes the current directory (e.g., |
|
Creates a new directory (e.g., |
|
Removes a directory (e.g., |
|
Copies files (e.g., |
|
Deletes files (e.g., |
Batch Scripting Advanced
Conditional Statements and Loops
|
|
|
Working with Strings
|
Substring extraction from a variable (e.g., |
|
String replacement (e.g., replace ‘old’ with ‘new’ in %variable%). |
|
Delete search string |
Calling External Programs
|
|