Scripting Languages Overview
PowerShell (.ps1): Microsoft's primary scripting language for Windows administration. Object-based output. Cmdlet-based syntax (Verb-Noun). Widely used for: Active Directory management, system configuration, automation, cloud management (Azure PowerShell). Execution policy controls whether scripts run. Batch files / CMD scripts (.bat, .cmd): legacy Windows scripting. Uses CMD commands. Simple but powerful for basic automation. Still widely used for compatibility. Python (.py): cross-platform, versatile scripting language. Used for: network automation, data processing, security scripting, web scraping, API interaction. Required by many modern tools and cloud platforms. Bash scripts (.sh): Linux/macOS shell scripting. Uses Linux commands. Essential for Linux server administration and DevOps. VBScript (.vbs): older Windows scripting language. Runs via Windows Script Host (wscript.exe or cscript.exe). Largely replaced by PowerShell. Still encountered in legacy enterprise environments. JavaScript (.js): web scripting and Node.js server-side scripting. Not typically used for Windows/Linux administration.
Script Fundamentals
Variables: store values for use throughout a script. PowerShell: $variableName = 'value'. Batch: SET variable=value, reference as %variable%. Python: variable_name = 'value' (no $ prefix). Bash: variable='value', reference as $variable. Conditional logic (if/else): execute different code based on conditions. PowerShell: if ($condition) { action } else { other }. Batch: IF condition (action). Loops: repeat code. For loop: repeat a set number of times. PowerShell: for ($i=0; $i -lt 10; $i++) { ... } or foreach ($item in $collection) { ... }. Batch: FOR %%v IN (values) DO (action). Python: for item in list: → action. Functions/subroutines: named blocks of reusable code. Error handling: try/catch blocks prevent script failure on errors. Comments: annotate code for readability. PowerShell: # comment. Batch: REM comment or :: comment. Python: # comment. Input/Output: read input from user or file; write output to screen, file, or log.
Common Scripting Use Cases
User account management: PowerShell script to create Active Directory accounts from a CSV file. Remove inactive accounts on a schedule. Password resets in bulk. System maintenance: scheduled cleanup of temporary files (PowerShell/batch). Automated disk space monitoring — alert when below threshold. Patch compliance reporting. Backup automation: PowerShell script to copy files to a network share and log success/failure. robocopy in a batch file for nightly backup runs. Network administration: PowerShell to query network adapter configuration across multiple computers. Bash script to ping a list of IPs and report unreachable hosts. Security automation: script to check for unauthorized local admin accounts. PowerShell to review audit log for failed login attempts. Reporting: generate daily system health reports as text files or HTML. Deployment: batch/PowerShell scripts for application installation during new machine setup.
Script Security
Scripts can be dangerous if misused or malicious. Malware in scripts: PowerShell is heavily abused by malware — fileless malware often uses PowerShell for command execution, download of payloads, lateral movement. PowerShell execution policy: Restricted (no scripts), AllSigned (all scripts must be signed), RemoteSigned (local scripts OK, remote must be signed), Unrestricted (all scripts). Default on Windows 10/11: Restricted. Change with: `Set-ExecutionPolicy RemoteSigned`. Script signing: PowerShell scripts can be digitally signed (code signing certificate) — prevents unauthorized modification. Script review: always review scripts from unknown sources before running. Never run scripts as administrator without understanding what they do. Obfuscated PowerShell: malware uses base64 encoding and other obfuscation to hide script content from detection. `-EncodedCommand` flag is a red flag in unexpected contexts. Secure script storage: store scripts in access-controlled locations. Don't embed credentials in scripts (use credential stores or secure vaults).